mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
For images that include SMask/Mask entries, ignore an SMask defined in the current graphics state
From section [11.6.4.3 Mask Shape and Opacity](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G10.4848628) in the PDF specification: - An image XObject may contain its own *soft-mask image* in the form of a subsidiary image XObject in the `SMask` entry of the image dictionary (see "Image Dictionaries"). This mask, if present, shall override any explicit or colour key mask specified by the image dictionary's `Mask` entry. Either form of mask in the image dictionary shall override the current soft mask in the graphics state.
This commit is contained in:
parent
8a50d2d302
commit
20d5332009
5 changed files with 32 additions and 11 deletions
|
@ -175,7 +175,7 @@ function addLocallyCachedImageOps(opList, data) {
|
|||
if (data.objId) {
|
||||
opList.addDependency(data.objId);
|
||||
}
|
||||
opList.addImageOps(data.fn, data.args, data.optionalContent);
|
||||
opList.addImageOps(data.fn, data.args, data.optionalContent, data.hasMask);
|
||||
|
||||
if (data.fn === OPS.paintImageMaskXObject && data.args[0]?.count > 0) {
|
||||
data.args[0].count++;
|
||||
|
@ -730,13 +730,9 @@ class PartialEvaluator {
|
|||
}
|
||||
|
||||
const SMALL_IMAGE_DIMENSIONS = 200;
|
||||
const hasMask = dict.has("SMask") || dict.has("Mask");
|
||||
// Inlining small images into the queue as RGB data
|
||||
if (
|
||||
isInline &&
|
||||
w + h < SMALL_IMAGE_DIMENSIONS &&
|
||||
!dict.has("SMask") &&
|
||||
!dict.has("Mask")
|
||||
) {
|
||||
if (isInline && w + h < SMALL_IMAGE_DIMENSIONS && !hasMask) {
|
||||
try {
|
||||
const imageObj = new PDFImage({
|
||||
xref: this.xref,
|
||||
|
@ -793,7 +789,12 @@ class PartialEvaluator {
|
|||
// Ensure that the dependency is added before the image is decoded.
|
||||
operatorList.addDependency(objId);
|
||||
args = [objId, w, h];
|
||||
operatorList.addImageOps(OPS.paintImageXObject, args, optionalContent);
|
||||
operatorList.addImageOps(
|
||||
OPS.paintImageXObject,
|
||||
args,
|
||||
optionalContent,
|
||||
hasMask
|
||||
);
|
||||
|
||||
if (cacheGlobally) {
|
||||
if (this.globalImageCache.hasDecodeFailed(imageRef)) {
|
||||
|
@ -802,6 +803,7 @@ class PartialEvaluator {
|
|||
fn: OPS.paintImageXObject,
|
||||
args,
|
||||
optionalContent,
|
||||
hasMask,
|
||||
byteSize: 0, // Data is `null`, since decoding failed previously.
|
||||
});
|
||||
|
||||
|
@ -812,7 +814,7 @@ class PartialEvaluator {
|
|||
// For large (at least 500x500) or more complex images that we'll cache
|
||||
// globally, check if the image is still cached locally on the main-thread
|
||||
// to avoid having to re-parse the image (since that can be slow).
|
||||
if (w * h > 250000 || dict.has("SMask") || dict.has("Mask")) {
|
||||
if (w * h > 250000 || hasMask) {
|
||||
const localLength = await this.handler.sendWithPromise("commonobj", [
|
||||
objId,
|
||||
"CopyLocalImage",
|
||||
|
@ -825,6 +827,7 @@ class PartialEvaluator {
|
|||
fn: OPS.paintImageXObject,
|
||||
args,
|
||||
optionalContent,
|
||||
hasMask,
|
||||
byteSize: 0, // Temporary entry, to avoid `setData` returning early.
|
||||
});
|
||||
this.globalImageCache.addByteSize(imageRef, localLength);
|
||||
|
@ -872,6 +875,7 @@ class PartialEvaluator {
|
|||
fn: OPS.paintImageXObject,
|
||||
args,
|
||||
optionalContent,
|
||||
hasMask,
|
||||
};
|
||||
localImageCache.set(cacheKey, imageRef, cacheData);
|
||||
|
||||
|
@ -884,6 +888,7 @@ class PartialEvaluator {
|
|||
fn: OPS.paintImageXObject,
|
||||
args,
|
||||
optionalContent,
|
||||
hasMask,
|
||||
byteSize: 0, // Temporary entry, note `addByteSize` above.
|
||||
});
|
||||
}
|
||||
|
@ -1814,7 +1819,8 @@ class PartialEvaluator {
|
|||
operatorList.addImageOps(
|
||||
globalImage.fn,
|
||||
globalImage.args,
|
||||
globalImage.optionalContent
|
||||
globalImage.optionalContent,
|
||||
globalImage.hasMask
|
||||
);
|
||||
|
||||
resolveXObject();
|
||||
|
|
|
@ -636,7 +636,11 @@ class OperatorList {
|
|||
}
|
||||
}
|
||||
|
||||
addImageOps(fn, args, optionalContent) {
|
||||
addImageOps(fn, args, optionalContent, hasMask = false) {
|
||||
if (hasMask) {
|
||||
this.addOp(OPS.save);
|
||||
this.addOp(OPS.setGState, [[["SMask", false]]]);
|
||||
}
|
||||
if (optionalContent !== undefined) {
|
||||
this.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
|
||||
}
|
||||
|
@ -646,6 +650,9 @@ class OperatorList {
|
|||
if (optionalContent !== undefined) {
|
||||
this.addOp(OPS.endMarkedContent, []);
|
||||
}
|
||||
if (hasMask) {
|
||||
this.addOp(OPS.restore);
|
||||
}
|
||||
}
|
||||
|
||||
addDependency(dependency) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue