diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 2f0fe5821..90615b228 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -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( diff --git a/test/driver.js b/test/driver.js index 5946561a8..7f0d651e3 100644 --- a/test/driver.js +++ b/test/driver.js @@ -519,7 +519,7 @@ var Driver = (function DriverClosure() { styleElement: xfaStyleElement, }); loadingTask.promise.then( - doc => { + async doc => { if (task.enableXfa) { task.fontRules = ""; for (const rule of xfaStyleElement.sheet.cssRules) { @@ -531,6 +531,15 @@ var Driver = (function DriverClosure() { task.optionalContentConfigPromise = doc.getOptionalContentConfig(); + if (task.optionalContent) { + const entries = Object.entries(task.optionalContent), + optionalContentConfig = + await task.optionalContentConfigPromise; + for (const [id, visible] of entries) { + optionalContentConfig.setVisibility(id, visible); + } + } + this._nextPage(task, failure); }, err => { diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 41f4da7da..49aadc5b7 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -442,6 +442,7 @@ !issue8097_reduced.pdf !quadpoints.pdf !transparent.pdf +!issue13931.pdf !xobject-image.pdf !issue6605.pdf !ccitt_EndOfBlock_false.pdf diff --git a/test/pdfs/issue13931.pdf b/test/pdfs/issue13931.pdf new file mode 100644 index 000000000..f953c1e23 Binary files /dev/null and b/test/pdfs/issue13931.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 4826b45ab..3741652e1 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -5019,6 +5019,21 @@ "rounds": 1, "type": "eq" }, + { "id": "issue13931-default", + "file": "pdfs/issue13931.pdf", + "md5": "799d5025787115d22863ae23a3042491", + "rounds": 1, + "type": "eq" + }, + { "id": "issue13931-hidden", + "file": "pdfs/issue13931.pdf", + "md5": "799d5025787115d22863ae23a3042491", + "rounds": 1, + "type": "eq", + "optionalContent": { + "7R": false + } + }, { "id": "issue2829", "file": "pdfs/issue2829.pdf", "md5": "f32b28cf8792f6ccc470446bfbb38584",