Skip to content

Commit 0bd8f91

Browse files
committed
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.
1 parent bb81f40 commit 0bd8f91

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

src/core/evaluator.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,21 @@ class PartialEvaluator {
567567

568568
if (!(w && isNum(w)) || !(h && isNum(h))) {
569569
warn("Image dimensions are missing, or not numbers.");
570-
return undefined;
570+
return;
571571
}
572572
const maxImageSize = this.options.maxImageSize;
573573
if (maxImageSize !== -1 && w * h > maxImageSize) {
574574
warn("Image exceeded maximum allowed size and was removed.");
575-
return undefined;
575+
return;
576+
}
577+
578+
let optionalContent = null;
579+
if (dict.has("OC")) {
580+
optionalContent = await this.parseMarkedContentProps(
581+
dict.get("OC"),
582+
resources
583+
);
584+
operatorList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
576585
}
577586

578587
const imageMask = dict.get("ImageMask", "IM") || false;
@@ -610,7 +619,11 @@ class PartialEvaluator {
610619
args,
611620
});
612621
}
613-
return undefined;
622+
623+
if (optionalContent) {
624+
operatorList.addOp(OPS.endMarkedContent, []);
625+
}
626+
return;
614627
}
615628

616629
const softMask = dict.get("SMask", "SM") || false;
@@ -631,7 +644,11 @@ class PartialEvaluator {
631644
// any other kind.
632645
imgData = imageObj.createImageData(/* forceRGBA = */ true);
633646
operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
634-
return undefined;
647+
648+
if (optionalContent) {
649+
operatorList.addOp(OPS.endMarkedContent, []);
650+
}
651+
return;
635652
}
636653

637654
// If there is no imageMask, create the PDFImage and a lot
@@ -699,7 +716,10 @@ class PartialEvaluator {
699716
}
700717
}
701718
}
702-
return undefined;
719+
720+
if (optionalContent) {
721+
operatorList.addOp(OPS.endMarkedContent, []);
722+
}
703723
}
704724

705725
handleSMask(

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@
442442
!issue8097_reduced.pdf
443443
!quadpoints.pdf
444444
!transparent.pdf
445+
!issue13931.pdf
445446
!xobject-image.pdf
446447
!issue6605.pdf
447448
!ccitt_EndOfBlock_false.pdf

test/pdfs/issue13931.pdf

296 KB
Binary file not shown.

test/test_manifest.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5019,6 +5019,12 @@
50195019
"rounds": 1,
50205020
"type": "eq"
50215021
},
5022+
{ "id": "issue13931-default",
5023+
"file": "pdfs/issue13931.pdf",
5024+
"md5": "799d5025787115d22863ae23a3042491",
5025+
"rounds": 1,
5026+
"type": "eq"
5027+
},
50225028
{ "id": "issue2829",
50235029
"file": "pdfs/issue2829.pdf",
50245030
"md5": "f32b28cf8792f6ccc470446bfbb38584",

0 commit comments

Comments
 (0)