Merge pull request #16115 from calixteman/issue16114
Apply transfer filters to any graphic commands
This commit is contained in:
commit
a0ef5a4ae1
@ -38,6 +38,7 @@ import {
|
|||||||
TilingPattern,
|
TilingPattern,
|
||||||
} from "./pattern_helper.js";
|
} from "./pattern_helper.js";
|
||||||
import { convertBlackAndWhiteToRGBA } from "../shared/image_utils.js";
|
import { convertBlackAndWhiteToRGBA } from "../shared/image_utils.js";
|
||||||
|
import { isNodeJS } from "../shared/is_node.js";
|
||||||
|
|
||||||
// <canvas> contexts store most of the state we need natively.
|
// <canvas> contexts store most of the state we need natively.
|
||||||
// However, PDF needs a bit more state, which we store here.
|
// However, PDF needs a bit more state, which we store here.
|
||||||
@ -837,6 +838,7 @@ function copyCtxState(sourceCtx, destCtx) {
|
|||||||
"miterLimit",
|
"miterLimit",
|
||||||
"globalCompositeOperation",
|
"globalCompositeOperation",
|
||||||
"font",
|
"font",
|
||||||
|
"filter",
|
||||||
];
|
];
|
||||||
for (const property of properties) {
|
for (const property of properties) {
|
||||||
if (sourceCtx[property] !== undefined) {
|
if (sourceCtx[property] !== undefined) {
|
||||||
@ -863,6 +865,9 @@ function resetCtxToDefault(ctx, foregroundColor) {
|
|||||||
ctx.setLineDash([]);
|
ctx.setLineDash([]);
|
||||||
ctx.lineDashOffset = 0;
|
ctx.lineDashOffset = 0;
|
||||||
}
|
}
|
||||||
|
if (!isNodeJS) {
|
||||||
|
ctx.filter = "none";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function composeSMaskBackdrop(bytes, r0, g0, b0) {
|
function composeSMaskBackdrop(bytes, r0, g0, b0) {
|
||||||
@ -1586,9 +1591,12 @@ class CanvasGraphics {
|
|||||||
this.checkSMaskState();
|
this.checkSMaskState();
|
||||||
break;
|
break;
|
||||||
case "TR":
|
case "TR":
|
||||||
this.current.transferMaps = this.filterFactory
|
if (this.filterFactory) {
|
||||||
? this.filterFactory.addFilter(value)
|
this.ctx.filter = this.current.transferMaps =
|
||||||
: value;
|
this.filterFactory.addFilter(value);
|
||||||
|
} else {
|
||||||
|
this.current.transferMaps = value;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3035,7 +3043,7 @@ class CanvasGraphics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
applyTransferMapsToBitmap(imgData) {
|
applyTransferMapsToBitmap(imgData) {
|
||||||
if (!this.current.transferMaps) {
|
if (!this.current.transferMaps || this.current.transferMaps === "none") {
|
||||||
return imgData.bitmap;
|
return imgData.bitmap;
|
||||||
}
|
}
|
||||||
const { bitmap, width, height } = imgData;
|
const { bitmap, width, height } = imgData;
|
||||||
@ -3047,7 +3055,7 @@ class CanvasGraphics {
|
|||||||
const tmpCtx = tmpCanvas.context;
|
const tmpCtx = tmpCanvas.context;
|
||||||
tmpCtx.filter = this.current.transferMaps;
|
tmpCtx.filter = this.current.transferMaps;
|
||||||
tmpCtx.drawImage(bitmap, 0, 0);
|
tmpCtx.drawImage(bitmap, 0, 0);
|
||||||
tmpCtx.filter = "";
|
tmpCtx.filter = "none";
|
||||||
|
|
||||||
return tmpCanvas.canvas;
|
return tmpCanvas.canvas;
|
||||||
}
|
}
|
||||||
@ -3061,6 +3069,15 @@ class CanvasGraphics {
|
|||||||
const ctx = this.ctx;
|
const ctx = this.ctx;
|
||||||
|
|
||||||
this.save();
|
this.save();
|
||||||
|
|
||||||
|
if (!isNodeJS) {
|
||||||
|
// The filter, if any, will be applied in applyTransferMapsToBitmap.
|
||||||
|
// It must be applied to the image before rescaling else some artifacts
|
||||||
|
// could appear.
|
||||||
|
// The final restore will reset it to its value.
|
||||||
|
ctx.filter = "none";
|
||||||
|
}
|
||||||
|
|
||||||
// scale the image to the unit square
|
// scale the image to the unit square
|
||||||
ctx.scale(1 / width, -1 / height);
|
ctx.scale(1 / width, -1 / height);
|
||||||
|
|
||||||
@ -3116,7 +3133,7 @@ class CanvasGraphics {
|
|||||||
const ctx = this.ctx;
|
const ctx = this.ctx;
|
||||||
let imgToPaint;
|
let imgToPaint;
|
||||||
if (imgData.bitmap) {
|
if (imgData.bitmap) {
|
||||||
imgToPaint = this.applyTransferMapsToBitmap(imgData);
|
imgToPaint = imgData.bitmap;
|
||||||
} else {
|
} else {
|
||||||
const w = imgData.width;
|
const w = imgData.width;
|
||||||
const h = imgData.height;
|
const h = imgData.height;
|
||||||
|
@ -81,7 +81,7 @@ class FilterFactory {
|
|||||||
|
|
||||||
addFilter(maps) {
|
addFilter(maps) {
|
||||||
if (!maps) {
|
if (!maps) {
|
||||||
return "";
|
return "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a page is zoomed the page is re-drawn but the maps are likely
|
// When a page is zoomed the page is re-drawn but the maps are likely
|
||||||
|
2
test/pdfs/issue16114.pdf.link
Normal file
2
test/pdfs/issue16114.pdf.link
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
https://github.com/mozilla/pdf.js/files/10896497/spider.pdf
|
||||||
|
|
@ -7447,5 +7447,13 @@
|
|||||||
"md5": "76d680172c969c77c9fb650b3d822ad6",
|
"md5": "76d680172c969c77c9fb650b3d822ad6",
|
||||||
"link": true,
|
"link": true,
|
||||||
"type": "other"
|
"type": "other"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "issue16114",
|
||||||
|
"file": "pdfs/issue16114.pdf",
|
||||||
|
"md5": "c04827ea33692e0f94a5e51716d9aa2e",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": true,
|
||||||
|
"type": "eq"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user