Skip to content

Commit f95939e

Browse files
committed
Also apply scale factor from transformation matrix
Unfortunately, Point class is not exported from jsPDF and cannot be used here with Matrix.applyToPoint method
1 parent d7d6cd5 commit f95939e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/nodes/group.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export class GroupA extends Group {
2323
const scale = context.pdf.internal.scaleFactor
2424
const ph = context.pdf.internal.pageSize.getHeight()
2525

26-
context.pdf.link(scale*(box[0] + context.transform.tx), ph - scale*(box[1] + context.transform.ty), scale*box[2], scale*box[3], { url: href })
26+
context.pdf.link(scale*(box[0] * context.transform.sx + context.transform.tx),
27+
ph - scale*(box[1] * context.transform.sy + context.transform.ty), scale*box[2], scale*box[3], { url: href })
2728
}
2829
}
2930
}

src/utils/bbox.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ export function getBoundingBoxByChildren(context: Context, svgnode: SvgNode): nu
1212
const nodeBox = child.getBoundingBox(context)
1313
if ((nodeBox[0] === 0) && (nodeBox[1] === 0) && (nodeBox[2] === 0) && (nodeBox[3] === 0))
1414
return;
15-
const transform = child.computeNodeTransform(context);
16-
// TODO: check and apply rotation matrix if any
17-
nodeBox[0] += transform.tx;
18-
nodeBox[1] += transform.ty;
15+
const transform = child.computeNodeTransform(context)
16+
nodeBox[0] = nodeBox[0] * transform.sx + transform.tx
17+
nodeBox[1] = nodeBox[1] * transform.sy + transform.ty
1918
if (boundingBox.length === 0)
2019
boundingBox = nodeBox;
2120
else

0 commit comments

Comments
 (0)