From 1c7048399bdcee27422c9d94c0d2f765de73e68b Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Thu, 4 Nov 2021 16:45:48 -0700 Subject: [PATCH] Use correct matrix for patterns with showText. We were incorrectly using the transform in the pattern before it had been adjusted causing the pattern to be misplaced relative to the page. Fixes: ShowText-ShadingPattern.pdf (already in corpus) Fixes: #8111 Fixes: #9243 --- src/display/canvas.js | 19 +++--- src/display/pattern_helper.js | 2 +- test/pdfs/.gitignore | 2 + test/pdfs/issue8111.pdf | Bin 0 -> 1272 bytes test/pdfs/issue9243.pdf | 110 ++++++++++++++++++++++++++++++++++ test/test_manifest.json | 12 ++++ 6 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 test/pdfs/issue8111.pdf create mode 100644 test/pdfs/issue9243.pdf diff --git a/src/display/canvas.js b/src/display/canvas.js index c29f1cc9f..a04b50b66 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -2146,10 +2146,17 @@ class CanvasGraphics { !current.patternFill; ctx.save(); + ctx.transform.apply(ctx, current.textMatrix); + ctx.translate(current.x, current.y + current.textRise); + + if (fontDirection > 0) { + ctx.scale(textHScale, -1); + } else { + ctx.scale(textHScale, 1); + } + let patternTransform; if (current.patternFill) { - // TODO: Patterns are not applied correctly to text if a non-embedded - // font is used. E.g. issue 8111 and ShowText-ShadingPattern.pdf. ctx.save(); const pattern = current.fillColor.getPattern( ctx, @@ -2160,14 +2167,6 @@ class CanvasGraphics { ctx.restore(); ctx.fillStyle = pattern; } - ctx.transform.apply(ctx, current.textMatrix); - ctx.translate(current.x, current.y + current.textRise); - - if (fontDirection > 0) { - ctx.scale(textHScale, -1); - } else { - ctx.scale(textHScale, 1); - } let lineWidth = current.lineWidth; let resetLineWidthToOne = false; diff --git a/src/display/pattern_helper.js b/src/display/pattern_helper.js index e6e112fe9..39ff3e572 100644 --- a/src/display/pattern_helper.js +++ b/src/display/pattern_helper.js @@ -112,7 +112,7 @@ class RadialAxialShadingPattern extends BaseShadingPattern { tmpCtx.fillStyle = this._createGradient(tmpCtx); tmpCtx.fill(); - pattern = ctx.createPattern(tmpCanvas.canvas, "repeat"); + pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat"); this.cachedCanvasPatterns.set(this, pattern); } } else { diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index f5828ff53..f84de5b8e 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -326,6 +326,7 @@ !bug1065245.pdf !issue6769.pdf !bug1151216.pdf +!issue8111.pdf !bug1175962.pdf !bug1020226.pdf !issue9534_reduced.pdf @@ -374,6 +375,7 @@ !issue4573.pdf !issue4722.pdf !issue4800.pdf +!issue9243.pdf !issue13147.pdf !issue11477_reduced.pdf !text_clip_cff_cid.pdf diff --git a/test/pdfs/issue8111.pdf b/test/pdfs/issue8111.pdf new file mode 100644 index 0000000000000000000000000000000000000000..de120ddb69fda09e998ef36a89becc54010af96e GIT binary patch literal 1272 zcmaJ>%}&%%6owEJ(?m%OBrflU071AvZD%@$OmsSo3Mx_yj2W0Qv%+J5wkDW0Ur#U(Y$;Ip23?W?J>eB3-hKneRWod^0E_ zNOqqX%geYf_j#Oj2%Swm>=t=%dDojK>5UWP^muah&U|z6 zQ+svk(bq}h&uxC5c*}e;R&%ep6BFd-$DhZ~OrMM&9e=Q1{QmQ9`qui?8e=b~*Sv+b zDce1|_iKFY)z36tV&FuqzVkq=GN4BCUgbt$NM5%tjS(D>U0RMB%p1a?Bd69azDx9^Y?bYtMoj2 zC|a1Md& _qfhPW!)6s;3|y=BXhxOZSmPOqeUoc=!Cq6D`gsH9ZFz5;I>95tcmQ& zw0*z>f$QRF90>104d;ZTa(HC`+J_yL_65?9V)2IbAl%u4X|r;^roZjau_d}xo-gdm zfUXawQoJ5RGumzMf|gE^uBoxh74OO2q0`xD6AG?M5e&wM{XnF1@zC=jE9xF1>YLmC zJl>FD9hQ5pewPu-h)FBNVT?Engw7H&JC9x1cKtj0Z&blNNJV6584YrNp^|NzHj2b=!vyM8;T_+^n$T5X&mAMFkQZP|AX%v&Tu#$T{ZXcGVc literal 0 HcmV?d00001 diff --git a/test/pdfs/issue9243.pdf b/test/pdfs/issue9243.pdf new file mode 100644 index 000000000..ad4b75932 --- /dev/null +++ b/test/pdfs/issue9243.pdf @@ -0,0 +1,110 @@ +%PDF-1.4 +1 0 obj +<< /Type /Catalog + /Outlines 2 0 R + /Pages 3 0 R +>> +endobj +2 0 obj +<< /Type /Outlines + /Count 0 +>> +endobj +3 0 obj +<< /Type /Pages + /Kids [ + 9 0 R + ] + /Count 1 +>> +endobj +4 0 obj +<< + /Title (Shading pattern test) + /Author (Luis) + /Producer (SciSoft PDF exporter) + /CreationDate (D:20171205161319-03'00') +>> +endobj +5 0 obj +<< /FunctionType 2 + /Domain [ 0.000000 1.000000 ] + /C0 [ 0.100000 0.700000 0.700000 ] + /C1 [ 0.000000 0.000000 0.700000 ] + /N 1.000000 +>> +endobj +6 0 obj +<< /ShadingType 2 + /ColorSpace /DeviceRGB + /Function 5 0 R + /Coords [ 0.000000 0.000000 432.000000 432.000000 ] + /Domain [ 0.000000 1.000000 ] + /Extend [ false false ] +>> +endobj +7 0 obj +<< /Type /Pattern + /PatternType 2 + /Shading 6 0 R +>> +endobj +8 0 obj +<< /Type /Font /Subtype /Type1 + /Name /F8 + /BaseFont /Helvetica-Bold + /Encoding /WinAnsiEncoding +>> +endobj +9 0 obj +<< /Type /Page + /Parent 3 0 R + /MediaBox [ 0 0 432 144 ] + /Contents 10 0 R + /Resources + << /ProcSet [ /PDF /Text ] + /Font << + /F8 8 0 R + >> + /Pattern << /PT7 7 0 R >> + >> +>> +endobj +10 0 obj +<< /Length 11 0 R >> +stream +/Pattern cs +/PT7 scn +BT +/F8 72 Tf +36 36 Td +0 Tr +(SHADING) Tj +ET +endstream +endobj +11 0 obj + 64 +endobj +xref +0 12 +0000000000 65535 f +0000000009 00000 n +0000000080 00000 n +0000000129 00000 n +0000000214 00000 n +0000000365 00000 n +0000000526 00000 n +0000000722 00000 n +0000000794 00000 n +0000000915 00000 n +0000001145 00000 n +0000001263 00000 n +trailer +<< /Size 12 + /Root 1 0 R + /Info 4 0 R +>> +startxref +1285 +%%EOF \ No newline at end of file diff --git a/test/test_manifest.json b/test/test_manifest.json index 4b97ddc7e..9649333f9 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -178,6 +178,12 @@ "rounds": 1, "type": "eq" }, + { "id": "issue8111", + "file": "pdfs/issue8111.pdf", + "md5": "14a2b3c19ed3d6cd7e138cdc141aa4a8", + "rounds": 1, + "type": "eq" + }, { "id": "issue13343", "file": "pdfs/issue13343.pdf", "md5": "f8bf1888839e15254555092c504e1900", @@ -2580,6 +2586,12 @@ "link": true, "type": "eq" }, + { "id": "issue9243", + "file": "pdfs/issue9243.pdf", + "md5": "f6b8c5c62b8875f7d9dfcd2b25d3aab8", + "rounds": 1, + "type": "eq" + }, { "id": "issue8424", "file": "pdfs/issue8424.pdf", "md5": "3de1ea4c085e8fe8e156153418058955",