diff --git a/src/display/canvas.js b/src/display/canvas.js index c483e5163..c43bc6a6a 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -1313,11 +1313,12 @@ class CanvasGraphics { 0, ]); maskToCanvas = Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]); - const cord1 = Util.applyTransform([0, 0], maskToCanvas); - const cord2 = Util.applyTransform([width, height], maskToCanvas); - const rect = Util.normalizeRect([cord1[0], cord1[1], cord2[0], cord2[1]]); - const drawnWidth = Math.round(rect[2] - rect[0]) || 1; - const drawnHeight = Math.round(rect[3] - rect[1]) || 1; + const [minX, minY, maxX, maxY] = Util.getAxialAlignedBoundingBox( + [0, 0, width, height], + maskToCanvas + ); + const drawnWidth = Math.round(maxX - minX) || 1; + const drawnHeight = Math.round(maxY - minY) || 1; const fillCanvas = this.cachedCanvases.getCanvas( "fillCanvas", drawnWidth, @@ -1329,8 +1330,8 @@ class CanvasGraphics { // If objToCanvas is [a,b,c,d,e,f] then: // - offsetX = min(a, c) + e // - offsetY = min(b, d) + f - const offsetX = Math.min(cord1[0], cord2[0]); - const offsetY = Math.min(cord1[1], cord2[1]); + const offsetX = minX; + const offsetY = minY; fillCtx.translate(-offsetX, -offsetY); fillCtx.transform(...maskToCanvas); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index f51c766b1..3eff1fe26 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -332,6 +332,7 @@ !issue5470.pdf !issue5501.pdf !issue5599.pdf +!issue17147.pdf !issue5747.pdf !issue6099.pdf !issue6336.pdf diff --git a/test/pdfs/issue17147.pdf b/test/pdfs/issue17147.pdf new file mode 100644 index 000000000..b1891be7f Binary files /dev/null and b/test/pdfs/issue17147.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index ce4728f65..6a2a5a2a3 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -32,6 +32,12 @@ "type": "eq", "renderTaskOnContinue": true }, + { "id": "issue17147", + "file": "pdfs/issue17147.pdf", + "md5": "47012ba13ee819ec0af278c9d943f010", + "rounds": 1, + "type": "eq" + }, { "id": "issue13130", "file": "pdfs/issue13130.pdf", "md5": "318518299132fe3b52252ca43a69a23e",