Skip to content

Commit

Permalink
Merge pull request #17148 from JT-External/support-rotated-imagemask
Browse files Browse the repository at this point in the history
Fix size of maskCanvas to draw image masks correctly
  • Loading branch information
Snuffleupagus authored Oct 20, 2023
2 parents 5f0e560 + 0eacd5c commit a4cd2ef
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 a4cd2ef

Please sign in to comment.