summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schwarz <michi.schwarz@gmail.com>2015-09-30 18:19:14 +0200
committerMichael Schwarz <michi.schwarz@gmail.com>2015-09-30 18:19:50 +0200
commitb74aa3b7ce691126216e659a06808905649dd37b (patch)
treecb5d00b77f240da3d010d99b17ce3c998b6fa697
parent7a0be0c8126945f7fa4b68cc9d93a73ef4341189 (diff)
downloadpogojig-b74aa3b7ce691126216e659a06808905649dd37b.tar.gz
pogojig-b74aa3b7ce691126216e659a06808905649dd37b.tar.bz2
pogojig-b74aa3b7ce691126216e659a06808905649dd37b.zip
Reject documents without absolute size.
Reject document which do not have a viewBox and a height attribute with absolute measures. In documents without these, the size of a pixel cannot be determined and the scale out the exported shape depends on the Inkscape version. This fixes #16.
-rw-r--r--support/inkscape/__main__.py1
-rw-r--r--support/inkscape/effect.py21
2 files changed, 22 insertions, 0 deletions
diff --git a/support/inkscape/__main__.py b/support/inkscape/__main__.py
index e68341e..78ffb55 100644
--- a/support/inkscape/__main__.py
+++ b/support/inkscape/__main__.py
@@ -41,6 +41,7 @@ def main(in_path, out_path):
try:
_, out_suffix = os.path.splitext(out_path)
+ effect.ExportEffect.check_document_units(in_path)
with util.TemporaryDirectory() as temp_dir:
temp_svg_path = os.path.join(temp_dir, os.path.basename(in_path))
diff --git a/support/inkscape/effect.py b/support/inkscape/effect.py
index 513169d..7d95193 100644
--- a/support/inkscape/effect.py
+++ b/support/inkscape/effect.py
@@ -3,6 +3,8 @@ Based on code from Aaron Spike. See http://www.bobcookdev.com/inkscape/inkscape-
"""
import pkgutil, os, re, collections, itertools
+from lxml import etree
+from lib import util
from . import inkex, simpletransform, cubicsuperpath, cspsubdiv, inkscape
@@ -241,3 +243,22 @@ class ExportEffect(inkex.Effect):
return '_'
else:
return re.sub('[^a-zA-Z0-9]', '_', layer.export_name)
+
+ @classmethod
+ def check_document_units(cls, path):
+ with open(path, 'r') as file:
+ p = etree.XMLParser(huge_tree = True)
+ document = etree.parse(file, parser = p)
+
+ height_attr = document.getroot().get('height')
+
+ if height_attr is None:
+ raise util.UserError('SVG document has no height attribute. See https://github.com/Feuermurmel/openscad-template/wiki/Absolute-Measurements')
+
+ _, height_unit = cls._parse_measure(height_attr)
+
+ if height_unit is None or height_unit == 'px':
+ raise util.UserError('Height of SVG document is not an absolute measure. See https://github.com/Feuermurmel/openscad-template/wiki/Absolute-Measurements')
+
+ if document.getroot().get('viewBox') is None:
+ raise util.UserError('SVG document has no viewBox attribute. See https://github.com/Feuermurmel/openscad-template/wiki/Absolute-Measurements')