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 99338cdc8..80bb792e1 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 000000000..de120ddb6 Binary files /dev/null and b/test/pdfs/issue8111.pdf differ 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 3c69a633b..9b67aec79 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",