Fixed the scaling issues with the svg export

This commit is contained in:
grbd 2016-03-21 19:34:33 +00:00
parent b272329384
commit 17b4edb94b
1 changed files with 20 additions and 3 deletions

View File

@ -1714,15 +1714,32 @@ class App(QtCore.QObject):
except:
return "Could not retrieve object: %s" % obj_name
# TODO needs size of board determining
# TODO needs seperate colours for CNCPath Export
# The line thickness is only affected by the scaling factor not the tool size
# Use the tool size to determine the scaling factor for line thickness
with self.proc_container.new("Exporting SVG") as proc:
exported_svg = obj.export_svg()
# Determine bounding area for svg export
svgwidth = obj.solid_geometry.bounds[2] - obj.solid_geometry.bounds[0]
svgheight = obj.solid_geometry.bounds[3] - obj.solid_geometry.bounds[1]
minx = obj.solid_geometry.bounds[0]
miny = obj.solid_geometry.bounds[1] - svgheight
svgwidth = str(svgwidth)
svgheight = str(svgheight)
minx = str(minx)
miny = str(miny)
uom = obj.units.lower()
svg_header = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" '
svg_header += 'width="50mm" height="50mm" viewBox="0 -50 50 50">'
svg_header += 'width="' + svgwidth + uom + '" '
svg_header += 'height="' + svgheight + uom + '" '
svg_header += 'viewBox="' + minx + ' ' + miny + ' ' + svgwidth + ' ' + svgheight + '">'
svg_header += '<g transform="scale(1,-1)">'
svg_footer = '</g> </svg>'
svg_elem = svg_header + obj.export_svg() + svg_footer
svg_elem = svg_header + exported_svg + svg_footer
doc = parse_xml_string(svg_elem)
with open(filename, 'w') as fp:
fp.write(doc.toprettyxml())