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.
This commit is contained in:
parent
7a0be0c812
commit
b74aa3b7ce
2 changed files with 22 additions and 0 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue