From d114f71feb7051f922fe02a02b81b34aeba2a631 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sat, 26 Oct 2024 14:14:44 +0200 Subject: [PATCH] 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. --- src/display/canvas.js | 15 +++++++-------- test/pdfs/.gitignore | 1 + test/pdfs/issue18956.pdf | Bin 0 -> 9204 bytes test/test_manifest.json | 7 +++++++ 4 files changed, 15 insertions(+), 8 deletions(-) create mode 100755 test/pdfs/issue18956.pdf diff --git a/src/display/canvas.js b/src/display/canvas.js index 814dc3d811f27..098741ce9d275 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -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(); } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 7af1f403d887e..b10be1106d6b6 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -679,3 +679,4 @@ !issue18036.pdf !issue18894.pdf !bug1922766.pdf +!issue18956.pdf diff --git a/test/pdfs/issue18956.pdf b/test/pdfs/issue18956.pdf new file mode 100755 index 0000000000000000000000000000000000000000..7f71918c691cdfa97fc531323773c1922bffc9b4 GIT binary patch literal 9204 zcmeHNdvp_38lS#P+FHeez|lH}SHULp%;a&>l#n#EwV|O2@~F6-B-1v~Wa4B>)2{6D z5TPzuL3wnS!Mabr7GP!lcWt0J_r zj1foGt?w60vZM)8*h<4#seu4l%hZc!onv6*SKTM36jVv6jf8a!e|UA`NIYTqYkt%=}lCQUaul3lZsTS2@*G`F(oK^)TGCCQ;^~`m!B_;L}NkZRb-Kg1*WzYX0LArBR>~YUCnMw1%k_sCsgI{Q-p?_mDH1eAGIVH8p(#ZYf*C-o?1eTG zX0S@t(=8PkOeKz3VS>8G-;$D&vXYX;rBJkGG6; z$JTQ2SoB{93J4ORIjlwlp&@iB%zeSrAQTaXC>V4Yj`j{pZf#ogwmW8{X>&jQMYq2? z>O@=8tGohxv2XmO6xTjuZQ6`K?`q5b<@7M)sJp*SE#4__81;Sm+QIc}OPdkb;J(Ky z6NX$^R6F_XQ{$=5Wkp|nclB|$uzlW-7jsWmVRdhxsJ}2|PUEBleg5>w{29Ald*C@g z#}0tX9=`9{NCPQ!{@1-Xxi}vW6UtDK5hx0l2`Yd?p?#{AclUOy{M6%%T0MK? zPODEXaVs$M)Q<;kS1P!bU~7;=}Py-`%2Oh(Rg18k^A$# zG3E^P{zYjMqlrO#>y7Itzp(X_*B6~`T)Ls3^5mX3$~Cn}+u=^<+^;9o8(w7nJ74Mh z(6lbD;B|2e=EV3wQBfs2>=2?-6+AnArXc%jvl@>^QV3#5CJV-9BC+ofC~=A zXczCZFr0yPds&YV#wuYgWjU*tb})#MneK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