Ensure that *all* errors are handled in rasterizeTextLayer
/rasterizeAnnotationLayer
Currently errors occurring within the `src/display/{text_layer, annotation_layer}.js` files are not being handled properly by the test-suite, and the tests simply time out rather than failing as intended. This makes it *very* easy to accidentally overlook a certain type of errors, see e.g. https://github.com/mozilla/pdf.js/pull/13055#discussion_r589005041, which this patch will thus prevent.
This commit is contained in:
parent
56fd01bf8d
commit
39cd844243
@ -74,6 +74,10 @@ var rasterizeTextLayer = (function rasterizeTextLayerClosure() {
|
||||
div.className = "textLayer";
|
||||
foreignObject.appendChild(div);
|
||||
|
||||
stylePromise
|
||||
.then(async cssRules => {
|
||||
style.textContent = cssRules;
|
||||
|
||||
// Rendering text layer as HTML.
|
||||
var task = pdfjsLib.renderTextLayer({
|
||||
textContent,
|
||||
@ -81,9 +85,9 @@ var rasterizeTextLayer = (function rasterizeTextLayerClosure() {
|
||||
viewport,
|
||||
enhanceTextSelection,
|
||||
});
|
||||
Promise.all([stylePromise, task.promise]).then(function (results) {
|
||||
await task.promise;
|
||||
|
||||
task.expandTextDivs(true);
|
||||
style.textContent = results[0];
|
||||
svg.appendChild(foreignObject);
|
||||
|
||||
// We need to have UTF-8 encoded XML.
|
||||
@ -99,6 +103,9 @@ var rasterizeTextLayer = (function rasterizeTextLayerClosure() {
|
||||
img.onerror = function (e) {
|
||||
reject(new Error("Error rasterizing text layer " + e));
|
||||
};
|
||||
})
|
||||
.catch(reason => {
|
||||
reject(new Error(`rasterizeTextLayer: "${reason?.message}".`));
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -208,7 +215,8 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
|
||||
div.className = "annotationLayer";
|
||||
|
||||
// Rendering annotation layer as HTML.
|
||||
stylePromise.then(function (common, overrides) {
|
||||
stylePromise
|
||||
.then(async (common, overrides) => {
|
||||
style.textContent = common + overrides;
|
||||
|
||||
var annotation_viewport = viewport.clone({ dontFlip: true });
|
||||
@ -226,7 +234,8 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
|
||||
// Inline SVG images from text annotations.
|
||||
var images = div.getElementsByTagName("img");
|
||||
var imagePromises = inlineAnnotationImages(images);
|
||||
var converted = Promise.all(imagePromises).then(function (data) {
|
||||
|
||||
await Promise.all(imagePromises).then(function (data) {
|
||||
var loadedPromises = [];
|
||||
for (var i = 0, ii = data.length; i < ii; i++) {
|
||||
images[i].src = data[i];
|
||||
@ -246,7 +255,6 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
|
||||
svg.appendChild(foreignObject);
|
||||
|
||||
// We need to have UTF-8 encoded XML.
|
||||
converted.then(function () {
|
||||
var svg_xml = unescape(
|
||||
encodeURIComponent(new XMLSerializer().serializeToString(svg))
|
||||
);
|
||||
@ -259,7 +267,9 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
|
||||
img.onerror = function (e) {
|
||||
reject(new Error("Error rasterizing annotation layer " + e));
|
||||
};
|
||||
});
|
||||
})
|
||||
.catch(reason => {
|
||||
reject(new Error(`rasterizeAnnotationLayer: "${reason?.message}".`));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user