1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 16:48:08 +02:00

Always fill the mask with the backdrop color

It fixes #18956.

In the patch #18029, for performance reasons and because I thought it was useless, I deliberately chose to not fill the mask
with the backdrop color when it's full black: it was a bad idea.
So in this patch we always add the backdrop color to the mask.
This commit is contained in:
Calixte Denizet 2024-10-26 14:14:44 +02:00
parent bde36f28be
commit d114f71feb
4 changed files with 15 additions and 8 deletions

View file

@ -1498,6 +1498,7 @@ class CanvasGraphics {
let maskY = layerOffsetY - maskOffsetY;
if (backdrop) {
const backdropRGB = Util.makeHexColor(...backdrop);
if (
maskX < 0 ||
maskY < 0 ||
@ -1511,16 +1512,14 @@ class CanvasGraphics {
);
const ctx = canvas.context;
ctx.drawImage(maskCanvas, -maskX, -maskY);
if (backdrop.some(c => c !== 0)) {
ctx.globalCompositeOperation = "destination-atop";
ctx.fillStyle = Util.makeHexColor(...backdrop);
ctx.fillRect(0, 0, width, height);
ctx.globalCompositeOperation = "source-over";
}
ctx.globalCompositeOperation = "destination-atop";
ctx.fillStyle = backdropRGB;
ctx.fillRect(0, 0, width, height);
ctx.globalCompositeOperation = "source-over";
maskCanvas = canvas.canvas;
maskX = maskY = 0;
} else if (backdrop.some(c => c !== 0)) {
} else {
maskCtx.save();
maskCtx.globalAlpha = 1;
maskCtx.setTransform(1, 0, 0, 1, 0, 0);
@ -1528,7 +1527,7 @@ class CanvasGraphics {
clip.rect(maskX, maskY, width, height);
maskCtx.clip(clip);
maskCtx.globalCompositeOperation = "destination-atop";
maskCtx.fillStyle = Util.makeHexColor(...backdrop);
maskCtx.fillStyle = backdropRGB;
maskCtx.fillRect(maskX, maskY, width, height);
maskCtx.restore();
}