Extract the actual sending of image data from the PartialEvaluator.buildPaintImageXObject method

After PRs 10727 and 11912, the code responsible for sending the decoded image data to the main-thread has now become a fair bit more involved the previously.
To reduce the amount of duplication here, the actual code responsible for sending the data is thus extracted into a new helper method instead.
This commit is contained in:
Jonas Jenwald 2020-06-07 12:01:51 +02:00
parent aff0d56326
commit df7d8c74ca

View File

@ -439,6 +439,30 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
});
},
_sendImgData(objId, imgData, cacheGlobally = false) {
const transfers = imgData ? [imgData.data.buffer] : null;
if (this.parsingType3Font) {
return this.handler.sendWithPromise(
"commonobj",
[objId, "FontType3Res", imgData],
transfers
);
}
if (cacheGlobally) {
return this.handler.send(
"commonobj",
[objId, "Image", imgData],
transfers
);
}
return this.handler.send(
"obj",
[objId, this.pageIndex, "Image", imgData],
transfers
);
},
async buildPaintImageXObject({
resources,
image,
@ -552,42 +576,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
.then(imageObj => {
imgData = imageObj.createImageData(/* forceRGBA = */ false);
if (this.parsingType3Font) {
return this.handler.sendWithPromise(
"commonobj",
[objId, "FontType3Res", imgData],
[imgData.data.buffer]
);
} else if (cacheGlobally) {
this.handler.send(
"commonobj",
[objId, "Image", imgData],
[imgData.data.buffer]
);
return undefined;
}
this.handler.send(
"obj",
[objId, this.pageIndex, "Image", imgData],
[imgData.data.buffer]
);
return undefined;
return this._sendImgData(objId, imgData, cacheGlobally);
})
.catch(reason => {
warn("Unable to decode image: " + reason);
if (this.parsingType3Font) {
return this.handler.sendWithPromise("commonobj", [
objId,
"FontType3Res",
null,
]);
} else if (cacheGlobally) {
this.handler.send("commonobj", [objId, "Image", null]);
return undefined;
}
this.handler.send("obj", [objId, this.pageIndex, "Image", null]);
return undefined;
return this._sendImgData(objId, /* imgData = */ null, cacheGlobally);
});
if (this.parsingType3Font) {