Merge pull request #13932 from Snuffleupagus/oc-images
Support Optional Content in Image-/XObjects (issue 13931)
This commit is contained in:
commit
306119b12a
@ -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(
|
||||
|
@ -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 => {
|
||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -442,6 +442,7 @@
|
||||
!issue8097_reduced.pdf
|
||||
!quadpoints.pdf
|
||||
!transparent.pdf
|
||||
!issue13931.pdf
|
||||
!xobject-image.pdf
|
||||
!issue6605.pdf
|
||||
!ccitt_EndOfBlock_false.pdf
|
||||
|
BIN
test/pdfs/issue13931.pdf
Normal file
BIN
test/pdfs/issue13931.pdf
Normal file
Binary file not shown.
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user