summaryrefslogtreecommitdiff
path: root/support/inkscape
diff options
context:
space:
mode:
Diffstat (limited to 'support/inkscape')
-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')