Skip to content

Commit

Permalink
Fix size of maskCanvas to draw image masks correctly
Browse files Browse the repository at this point in the history
Use existing helper to calculate the Box

Co-authored-by: Jonas Jenwald <[email protected]>

Ensure that there are non-zero

Co-authored-by: Jonas Jenwald <[email protected]>

Add a reference test for #17147
  • Loading branch information
JT-External committed Oct 20, 2023
1 parent 36c3c0a commit 0eacd5c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
!issue5470.pdf
!issue5501.pdf
!issue5599.pdf
!issue17147.pdf
!issue5747.pdf
!issue6099.pdf
!issue6336.pdf
Expand Down
Binary file added test/pdfs/issue17147.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0eacd5c

Please sign in to comment.