1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #13932 from Snuffleupagus/oc-images

Support Optional Content in Image-/XObjects (issue 13931)
This commit is contained in:
Brendan Dahl 2021-08-30 10:10:14 -07:00 committed by GitHub
commit 306119b12a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 9 deletions

View file

@ -461,13 +461,15 @@ class PartialEvaluator {
} else {
bbox = null;
}
let optionalContent = null,
groupOptions;
let optionalContent, groupOptions;
if (dict.has("OC")) {
optionalContent = await this.parseMarkedContentProps(
dict.get("OC"),
resources
);
}
if (optionalContent !== undefined) {
operatorList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
}
const group = dict.get("Group");
@ -528,7 +530,7 @@ class PartialEvaluator {
operatorList.addOp(OPS.endGroup, [groupOptions]);
}
if (optionalContent) {
if (optionalContent !== undefined) {
operatorList.addOp(OPS.endMarkedContent, []);
}
});
@ -567,12 +569,23 @@ class PartialEvaluator {
if (!(w && isNum(w)) || !(h && isNum(h))) {
warn("Image dimensions are missing, or not numbers.");
return undefined;
return;
}
const maxImageSize = this.options.maxImageSize;
if (maxImageSize !== -1 && w * h > maxImageSize) {
warn("Image exceeded maximum allowed size and was removed.");
return undefined;
return;
}
let optionalContent;
if (dict.has("OC")) {
optionalContent = await this.parseMarkedContentProps(
dict.get("OC"),
resources
);
}
if (optionalContent !== undefined) {
operatorList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
}
const imageMask = dict.get("ImageMask", "IM") || false;
@ -610,7 +623,11 @@ class PartialEvaluator {
args,
});
}
return undefined;
if (optionalContent !== undefined) {
operatorList.addOp(OPS.endMarkedContent, []);
}
return;
}
const softMask = dict.get("SMask", "SM") || false;
@ -631,7 +648,11 @@ class PartialEvaluator {
// any other kind.
imgData = imageObj.createImageData(/* forceRGBA = */ true);
operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
return undefined;
if (optionalContent !== undefined) {
operatorList.addOp(OPS.endMarkedContent, []);
}
return;
}
// If there is no imageMask, create the PDFImage and a lot
@ -699,7 +720,10 @@ class PartialEvaluator {
}
}
}
return undefined;
if (optionalContent !== undefined) {
operatorList.addOp(OPS.endMarkedContent, []);
}
}
handleSMask(