Inkscape export: Fix wrong units in Asymptote export.

The generate asymptote file would use the Inkscape document coordinates but Asymptote always uses PostScript points.
This commit is contained in:
Michael Schwarz 2015-08-06 17:32:53 +02:00
parent 0b1113d503
commit 6bce36b6ed
2 changed files with 16 additions and 17 deletions

View file

@ -97,19 +97,16 @@ class ExportEffect(inkex.Effect):
self._layers_by_inkscape_name = { i.inkscape_name: i for i in self._layers }
user_unit = self._get_user_unit()
document_unit = self._get_document_unit()
height = self._measure_to_pixels(self._get_document_height_attr())
document_transform = simpletransform.composeTransform(
[[1 / document_unit, 0, 0], [0, 1 / document_unit, 0]],
[[1, 0, 0], [0, -1, height]])
document_height = self._measure_to_pixels(self._get_document_height_attr())
document_transform = [[1, 0, 0], [0, -1, document_height]]
element_transform = [[user_unit, 0, 0], [0, user_unit, 0]]
for node in self.document.getroot().xpath('//svg:path', namespaces = inkex.NSS):
self._add_shape(node, document_transform, element_transform)
def write_dxf(self, file):
document_unit = self._get_document_unit()
layer_indices = { l: i for i, l in enumerate(self._layers) }
file.write(pkgutil.get_data(__name__, 'dxf_header.txt'))
@ -120,19 +117,19 @@ class ExportEffect(inkex.Effect):
handle = 256
for layer, points in self._paths:
for (x1, y1), (x2, y2) in zip(points, points[1:]):
for layer, path in self._paths:
for (x1, y1), (x2, y2) in zip(path, path[1:]):
write_instruction(0, 'LINE')
write_instruction(8, layer.export_name)
write_instruction(62, layer_indices.get(layer, 0))
write_instruction(5, '{:x}'.format(handle))
write_instruction(100, 'AcDbEntity')
write_instruction(100, 'AcDbLine')
write_instruction(10, repr(x1))
write_instruction(20, repr(y1))
write_instruction(10, repr(x1 / document_unit))
write_instruction(20, repr(y1 / document_unit))
write_instruction(30, 0.0)
write_instruction(11, repr(x2))
write_instruction(21, repr(y2))
write_instruction(11, repr(x2 / document_unit))
write_instruction(21, repr(y2 / document_unit))
write_instruction(31, 0.0)
handle += 1
@ -143,6 +140,8 @@ class ExportEffect(inkex.Effect):
def write_line(format, *args):
print >> file, format.format(*args) + ';'
# Scales pixels to points.
unit_factor = self._unit_factors['pt']
lines_by_layer_name = collections.defaultdict(list)
for layer, path in self._paths:
@ -152,7 +151,7 @@ class ExportEffect(inkex.Effect):
write_line('path[] {}', layer_name)
for path in paths:
point_strs = ['({}, {})'.format(x, y) for x, y in path]
point_strs = ['({}, {})'.format(x / unit_factor, y / unit_factor) for x, y in path]
# Hack. We should determine from whether Z or z was used to close the path in the SVG document.
if path[0] == path[-1]:

View file

@ -14,17 +14,17 @@ def get_inkscape_layers(svg_path):
inkscape_name = i.get('{http://www.inkscape.org/namespaces/inkscape}label').strip()
if inkscape_name.endswith(']'):
dxf_name, args = inkscape_name[:-1].rsplit('[', 1)
export_name, args = inkscape_name[:-1].rsplit('[', 1)
dxf_name = dxf_name.strip()
export_name = export_name.strip()
args = args.strip()
use_paths = 'p' in args
else:
use_paths = False
dxf_name = inkscape_name
export_name = inkscape_name
yield Layer(inkscape_name, dxf_name, use_paths = use_paths)
yield Layer(inkscape_name, export_name, use_paths)
return list(iter_layers())