summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2018-06-10 15:31:10 -0400
committerLex Neva <github.com@lexneva.name>2018-06-10 15:31:10 -0400
commit406032c0f76a6caf1657d13d2b0956551fb7c726 (patch)
tree18134e00b1d4579be99c0ac56664a416636721f8
parentd06ff488f0977ab52dbf0169d85cc5d7a413e079 (diff)
handle SVG with no width/height
-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])