Support Optional Content in Image-/XObjects (issue 13931)

Currently, in the `PartialEvaluator`, we only support Optional Content in Form-/XObjects. Hence this patch adds support for Image-/XObjects as well, which looks like a simple oversight in PR 12095 since the canvas-implementation already contains the necessary code to support this.
This commit is contained in:
Jonas Jenwald 2021-08-24 11:30:19 +02:00
parent ada283cc35
commit 853b1172a1
4 changed files with 32 additions and 5 deletions

View File

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

View File

@ -442,6 +442,7 @@
!issue8097_reduced.pdf !issue8097_reduced.pdf
!quadpoints.pdf !quadpoints.pdf
!transparent.pdf !transparent.pdf
!issue13931.pdf
!xobject-image.pdf !xobject-image.pdf
!issue6605.pdf !issue6605.pdf
!ccitt_EndOfBlock_false.pdf !ccitt_EndOfBlock_false.pdf

BIN
test/pdfs/issue13931.pdf Normal file

Binary file not shown.

View File

@ -5019,6 +5019,12 @@
"rounds": 1, "rounds": 1,
"type": "eq" "type": "eq"
}, },
{ "id": "issue13931-default",
"file": "pdfs/issue13931.pdf",
"md5": "799d5025787115d22863ae23a3042491",
"rounds": 1,
"type": "eq"
},
{ "id": "issue2829", { "id": "issue2829",
"file": "pdfs/issue2829.pdf", "file": "pdfs/issue2829.pdf",
"md5": "f32b28cf8792f6ccc470446bfbb38584", "md5": "f32b28cf8792f6ccc470446bfbb38584",