From a3c31904f17b5ae3c9608c7ff56aa65dec2b1716 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sun, 23 Mar 2025 19:19:58 +0100 Subject: [PATCH] Take into account the group bbox It fixes #16742. --- src/display/canvas.js | 13 ++- test/pdfs/.gitignore | 1 + test/pdfs/issue16742.pdf | 189 +++++++++++++++++++++++++++++++++++++++ test/test_manifest.json | 7 ++ 4 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/issue16742.pdf diff --git a/src/display/canvas.js b/src/display/canvas.js index 118eed934..3310e512b 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -1380,7 +1380,7 @@ class CanvasGraphics { this.suspendedCtx = this.ctx; this.ctx = scratchCanvas.context; const ctx = this.ctx; - ctx.setTransform(...getCurrentTransform(this.suspendedCtx)); + ctx.setTransform(this.suspendedCtx.getTransform()); copyCtxState(this.suspendedCtx, ctx); mirrorContextOperations(ctx, this.suspendedCtx); @@ -2551,6 +2551,17 @@ class CanvasGraphics { groupCtx.translate(-offsetX, -offsetY); groupCtx.transform(...currentTransform); + // Apply the bbox to the group context. + let clip = new Path2D(); + const [x0, y0, x1, y1] = group.bbox; + clip.rect(x0, y0, x1 - x0, y1 - y0); + if (group.matrix) { + const path = new Path2D(); + path.addPath(clip, new DOMMatrix(group.matrix)); + clip = path; + } + groupCtx.clip(clip); + if (group.smask) { // Saving state and cached mask to be used in setGState. this.smaskStack.push({ diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index f3885ae97..f56442665 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -716,3 +716,4 @@ !issue19633.pdf !issue19424.pdf !issue18529.pdf +!issue16742.pdf diff --git a/test/pdfs/issue16742.pdf b/test/pdfs/issue16742.pdf new file mode 100644 index 000000000..dcdca9832 --- /dev/null +++ b/test/pdfs/issue16742.pdf @@ -0,0 +1,189 @@ +%PDF-1.7 +%€€€€ + +1 0 obj +<< + /Type /Catalog + /Pages 2 0 R +>> +endobj + +2 0 obj +<< + /Type /Pages + /Count 1 + /Kids [3 0 R] +>> +endobj + +6 0 obj +<< + /Length 105 + /Type /XObject + /Subtype /Form + /Resources << + /ColorSpace << + /srgb [/CalRGB << + /WhitePoint [0.9505 1 1.0888] + /Gamma [2.2 2.2 2.2] + /Matrix [0.4124 0.2126 0.0193 0.3576 0.715 0.1192 0.1805 0.0722 0.9505] + >>] + >> + /ProcSet [/PDF /ImageC /ImageB] + >> + /Group << + /Type /Group + /S /Transparency + /I true + /K false + /CS [/CalRGB << + /WhitePoint [0.9505 1 1.0888] + /Gamma [2.2 2.2 2.2] + /Matrix [0.4124 0.2126 0.0193 0.3576 0.715 0.1192 0.1805 0.0722 0.9505] + >>] + >> + /BBox [-20 -20 80 220.00002] +>> +stream +q +q +1 0 0 1 0 0 cm +q +1 0 0 1 0 0 cm +/srgb CS +/srgb cs +1 1 1 scn +0 0 m +200 0 l +200 200 l +0 200 l +h +f +Q +Q +Q +endstream +endobj + +7 0 obj +<< + /Type /ExtGState + /SMask << + /Type /Mask + /S /Luminosity + /G 6 0 R + >> +>> +endobj + +5 0 obj +<< + /Length 174 + /Type /XObject + /Subtype /Form + /Resources << + /ColorSpace << + /srgb [/CalRGB << + /WhitePoint [0.9505 1 1.0888] + /Gamma [2.2 2.2 2.2] + /Matrix [0.4124 0.2126 0.0193 0.3576 0.715 0.1192 0.1805 0.0722 0.9505] + >>] + >> + /ProcSet [/PDF /ImageC /ImageB] + /ExtGState << + /gs0 7 0 R + >> + >> + /BBox [0 0 200 200] + /Group << + /Type /Group + /S /Transparency + /I true + /K false + /CS [/CalRGB << + /WhitePoint [0.9505 1 1.0888] + /Gamma [2.2 2.2 2.2] + /Matrix [0.4124 0.2126 0.0193 0.3576 0.715 0.1192 0.1805 0.0722 0.9505] + >>] + >> +>> +stream +q +1 0 0 -1 0 200 cm +q +0.9848077 0.17364818 -0.17364818 0.9848077 0 0 cm +/gs0 gs +q +1 0 0 1 0 0 cm +/srgb CS +/srgb cs +0 0.5019608 0 scn +0 0 m +200 0 l +200 200 l +0 200 l +h +f +Q +Q +Q +endstream +endobj + +4 0 obj +<< + /Length 7 +>> +stream +/xo0 Do +endstream +endobj + +3 0 obj +<< + /Type /Page + /Resources << + /ColorSpace << + /srgb [/CalRGB << + /WhitePoint [0.9505 1 1.0888] + /Gamma [2.2 2.2 2.2] + /Matrix [0.4124 0.2126 0.0193 0.3576 0.715 0.1192 0.1805 0.0722 0.9505] + >>] + >> + /ProcSet [/PDF /ImageC /ImageB] + /XObject << + /xo0 5 0 R + >> + >> + /MediaBox [0 0 200 200] + /Parent 2 0 R + /Contents 4 0 R +>> +endobj + +8 0 obj +<< + /Producer (svg2pdf) +>> +endobj + +xref +0 9 +0000000000 65535 f +0000000016 00000 n +0000000070 00000 n +0000001875 00000 n +0000001816 00000 n +0000000977 00000 n +0000000134 00000 n +0000000871 00000 n +0000002275 00000 n +trailer +<< + /Size 9 + /Root 1 0 R + /Info 8 0 R +>> +startxref +2319 +%%EOF \ No newline at end of file diff --git a/test/test_manifest.json b/test/test_manifest.json index 2c20a1b70..bdfb25b02 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -12019,5 +12019,12 @@ "md5": "f95d2cbdd904f5acf922e088cc3cb153", "rounds": 1, "type": "eq" + }, + { + "id": "issue16742", + "file": "pdfs/issue16742.pdf", + "md5": "98b19e944339c01c10c503685eee3ad2", + "rounds": 1, + "type": "eq" } ]