summaryrefslogtreecommitdiff
path: root/support/inkscape
diff options
context:
space:
mode:
authorMichael Schwarz <michi.schwarz@gmail.com>2015-08-06 17:32:53 +0200
committerMichael Schwarz <michi.schwarz@gmail.com>2015-08-07 02:03:28 +0200
commit6bce36b6ede16d28626d40a0b4d60954a35ad48f (patch)
treeb2224d57fad10567da7a322d5b8843a13fe5b2e6 /support/inkscape
parent0b1113d5036c2f2ac4bceedfd907fcbbfea6f08e (diff)
downloadpogojig-6bce36b6ede16d28626d40a0b4d60954a35ad48f.tar.gz
pogojig-6bce36b6ede16d28626d40a0b4d60954a35ad48f.tar.bz2
pogojig-6bce36b6ede16d28626d40a0b4d60954a35ad48f.zip
Inkscape export: Fix wrong units in Asymptote export.
The generate asymptote file would use the Inkscape document coordinates but Asymptote always uses PostScript points.
Diffstat (limited to 'support/inkscape')
-rw-r--r--support/inkscape/effect.py25
-rw-r--r--support/inkscape/inkscape.py8
2 files changed, 16 insertions, 17 deletions
diff --git a/support/inkscape/effect.py b/support/inkscape/effect.py
index 5fe0daf..c111926 100644
--- a/support/inkscape/effect.py
+++ b/support/inkscape/effect.py
@@ -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]:
diff --git a/support/inkscape/inkscape.py b/support/inkscape/inkscape.py
index 09e7a7b..876b0a7 100644
--- a/support/inkscape/inkscape.py
+++ b/support/inkscape/inkscape.py
@@ -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())