1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Fix size of maskCanvas to draw image masks correctly

Use existing helper to calculate the Box

Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>

Ensure that there are non-zero

Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>

Add a reference test for #17147
This commit is contained in:
JT-External 2023-10-20 01:03:23 +09:00
parent 36c3c0a4c1
commit 0eacd5c107
4 changed files with 15 additions and 7 deletions

View file

@ -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);