summaryrefslogtreecommitdiff
path: root/lib/svg/units.py
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2018-06-15 21:42:52 -0400
committerGitHub <noreply@github.com>2018-06-15 21:42:52 -0400
commit28e8efebf2a721239fa996865f9ef228e3521121 (patch)
tree89526b299ab2e55bb69225d26cea781f90bc9bd1 /lib/svg/units.py
parent4a2162e25892da7ce49b944532ebc8f2a9786a28 (diff)
parent350c292f8d0415fefefa83ce5ce84c2b5c17bd75 (diff)
v1.9.1: bug fixes
Lots of bug fixes: * properly handle case where stroke width is not set (defaults to 1 per SVG spec) * properly handle case where <svg> width and height not set (defaults to viewbox) * properly handle case where fill is not set (defaults to "black" rather than "none") * show error message (rather than crashing) if satin column set for a path with only one subpath * don't leave the simulate window around after "use last settings" * show a useful error message in Params if the user hasn't selected anything embroiderable
Diffstat (limited to 'lib/svg/units.py')
-rw-r--r--lib/svg/units.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/svg/units.py b/lib/svg/units.py
index 015da60e..126027bc 100644
--- a/lib/svg/units.py
+++ b/lib/svg/units.py
@@ -75,11 +75,24 @@ def convert_length(length):
raise ValueError(_("Unknown unit: %s") % units)
+@cache
+def get_viewbox(svg):
+ return svg.get('viewBox').strip().replace(',', ' ').split()
+
@cache
def get_doc_size(svg):
- doc_width = convert_length(svg.get('width'))
- doc_height = convert_length(svg.get('height'))
+ width = svg.get('width')
+ height = svg.get('height')
+
+ if width is None or height is None:
+ # fall back to the dimensions from the viewBox
+ viewbox = get_viewbox(svg)
+ width = viewbox[2]
+ height = viewbox[3]
+
+ doc_width = convert_length(width)
+ doc_height = convert_length(height)
return doc_width, doc_height
@@ -88,7 +101,7 @@ def get_viewbox_transform(node):
# somewhat cribbed from inkscape-silhouette
doc_width, doc_height = get_doc_size(node)
- viewbox = node.get('viewBox').strip().replace(',', ' ').split()
+ viewbox = get_viewbox(node)
dx = -float(viewbox[0])
dy = -float(viewbox[1])