Skip to content

Commit

Permalink
Merge pull request #18960 from calixteman/issue18956
Browse files Browse the repository at this point in the history
Always fill the mask with the backdrop color
  • Loading branch information
calixteman authored Oct 26, 2024
2 parents bde36f2 + d114f71 commit 0d42e56
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,7 @@ class CanvasGraphics {
let maskY = layerOffsetY - maskOffsetY;

if (backdrop) {
const backdropRGB = Util.makeHexColor(...backdrop);
if (
maskX < 0 ||
maskY < 0 ||
Expand All @@ -1511,24 +1512,22 @@ 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);
const clip = new Path2D();
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();
}
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,4 @@
!issue18036.pdf
!issue18894.pdf
!bug1922766.pdf
!issue18956.pdf
Binary file added test/pdfs/issue18956.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10734,5 +10734,12 @@
"type": "eq",
"link": true,
"talos": false
},
{
"id": "issue18956",
"file": "pdfs/issue18956.pdf",
"md5": "73e8cd32bd063e42fcc4b270c78549b1",
"rounds": 1,
"type": "eq"
}
]

0 comments on commit 0d42e56

Please sign in to comment.