viewBox error fix in imagetracer.js

This commit is contained in:
Mario Voigt 2021-03-09 13:39:53 +01:00
parent f1f995c392
commit 9e98e7e842
2 changed files with 12 additions and 3 deletions

View File

@ -37,7 +37,7 @@
<param name="linefilter" type="bool" gui-text="Noise reduction line filter">false</param>
<!--<param name="scale" type="float" min="0.0" max="9999" gui-text="Coordinate scale factor">1.0</param> disabled because we resize to the size of the original image-->
<param name="roundcoords" type="int" min="0" max="10" gui-text="Decimal places for rounding">1</param>
<param name="viewbox" type="bool" gui-text="Enable or disable SVG viewBox">false</param>
<param name="viewbox" type="bool" gui-text="Resize to SVG viewBox">false</param>
<param name="desc" type="bool" gui-text="SVG descriptions">false</param>
<spacer/>
<label appearance="header">Blur Preprocessing</label>

View File

@ -142,10 +142,19 @@ class Imagetracerjs (inkex.Effect):
# new parse the SVG file and insert it as new group into the current document tree
doc = etree.parse(exportfile + ".svg").getroot()
newGroup = self.document.getroot().add(inkex.Group())
trace_width = None
trace_height = None
if doc.get('width') is not None and doc.get('height') is not None:
trace_width = doc.get('width')
trace_height = doc.get('height')
else:
viewBox = doc.get('viewBox') #eg "0 0 700 600"
trace_width = viewBox.split(' ')[2]
trace_height = viewBox.split(' ')[3]
newGroup.attrib['transform'] = "matrix(" + \
str(float(node.get('width')) / float(doc.get('width'))) + \
str(float(node.get('width')) / float(trace_width)) + \
", 0, 0 , " + \
str(float(node.get('height')) / float(doc.get('height'))) + \
str(float(node.get('height')) / float(trace_height)) + \
"," + node.get('x') + \
"," + node.get('y') + ")"
newGroup.append(doc)