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 { } else {
bbox = null; bbox = null;
} }
let optionalContent = null,
groupOptions; let optionalContent, groupOptions;
if (dict.has("OC")) { if (dict.has("OC")) {
optionalContent = await this.parseMarkedContentProps( optionalContent = await this.parseMarkedContentProps(
dict.get("OC"), dict.get("OC"),
resources resources
); );
}
if (optionalContent !== undefined) {
operatorList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]); operatorList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
} }
const group = dict.get("Group"); const group = dict.get("Group");
@ -528,7 +530,7 @@ class PartialEvaluator {
operatorList.addOp(OPS.endGroup, [groupOptions]); operatorList.addOp(OPS.endGroup, [groupOptions]);
} }
if (optionalContent) { if (optionalContent !== undefined) {
operatorList.addOp(OPS.endMarkedContent, []); operatorList.addOp(OPS.endMarkedContent, []);
} }
}); });
@ -567,12 +569,23 @@ 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;
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; const imageMask = dict.get("ImageMask", "IM") || false;
@ -610,7 +623,11 @@ class PartialEvaluator {
args, args,
}); });
} }
return undefined;
if (optionalContent !== undefined) {
operatorList.addOp(OPS.endMarkedContent, []);
}
return;
} }
const softMask = dict.get("SMask", "SM") || false; const softMask = dict.get("SMask", "SM") || false;
@ -631,7 +648,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 !== undefined) {
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 +720,10 @@ class PartialEvaluator {
} }
} }
} }
return undefined;
if (optionalContent !== undefined) {
operatorList.addOp(OPS.endMarkedContent, []);
}
} }
handleSMask( handleSMask(

View File

@ -519,7 +519,7 @@ var Driver = (function DriverClosure() {
styleElement: xfaStyleElement, styleElement: xfaStyleElement,
}); });
loadingTask.promise.then( loadingTask.promise.then(
doc => { async doc => {
if (task.enableXfa) { if (task.enableXfa) {
task.fontRules = ""; task.fontRules = "";
for (const rule of xfaStyleElement.sheet.cssRules) { for (const rule of xfaStyleElement.sheet.cssRules) {
@ -531,6 +531,15 @@ var Driver = (function DriverClosure() {
task.optionalContentConfigPromise = task.optionalContentConfigPromise =
doc.getOptionalContentConfig(); 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); this._nextPage(task, failure);
}, },
err => { err => {

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,21 @@
"rounds": 1, "rounds": 1,
"type": "eq" "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", { "id": "issue2829",
"file": "pdfs/issue2829.pdf", "file": "pdfs/issue2829.pdf",
"md5": "f32b28cf8792f6ccc470446bfbb38584", "md5": "f32b28cf8792f6ccc470446bfbb38584",