Fix 'translate' in SvgToPdf

This commit is contained in:
pietervdvn 2022-09-22 00:35:37 +02:00
parent b4df711d37
commit ee93c70867

View file

@ -67,12 +67,21 @@ class SvgToPdfInternals {
if (t === null) { if (t === null) {
return null; return null;
} }
const scaleMatch = t.match(/scale\(([-0-9.]*)\)/) const scaleMatch = t.match(/scale\(([-0-9.]+)\)/)
if (scaleMatch !== null) { if (scaleMatch !== null) {
const s = Number(scaleMatch[1]) const s = Number(scaleMatch[1])
return SvgToPdfInternals.dummyDoc.Matrix(1 / s, 0, 0, 1 / s, 0, 0); return SvgToPdfInternals.dummyDoc.Matrix(1 / s, 0, 0, 1 / s, 0, 0);
} }
const translateMatch = t.match(/translate\(([-0-9.]+), ?([-0-9.]*)\)/)
if (translateMatch !== null) {
const dx = Number(translateMatch[1])
const dy = Number(translateMatch[2])
console.log("Translating", dx, dy)
return SvgToPdfInternals.dummyDoc.Matrix(1, 0, 0, 1, dx, dy);
}
const transformMatch = t.match(/matrix\(([-0-9.]*),([-0-9.]*),([-0-9.]*),([-0-9.]*),([-0-9.]*),([-0-9.]*)\)/) const transformMatch = t.match(/matrix\(([-0-9.]*),([-0-9.]*),([-0-9.]*),([-0-9.]*),([-0-9.]*),([-0-9.]*)\)/)
if (transformMatch !== null) { if (transformMatch !== null) {
const vals = [1, 0, 0, 1, 0, 0] const vals = [1, 0, 0, 1, 0, 0]
@ -449,6 +458,9 @@ class SvgToPdfInternals {
} }
public handleElement(element: SVGSVGElement | Element): void { public handleElement(element: SVGSVGElement | Element): void {
if(element.id === "path15616"){
console.log("Handling element", element)
}
const isTransformed = this.setTransform(element) const isTransformed = this.setTransform(element)
try { try {