From db5685359f4e9b5e0a8dd4f5d526405a9795233c Mon Sep 17 00:00:00 2001 From: RJ Adriaansen Date: Sat, 30 Jul 2022 08:36:27 +0200 Subject: [PATCH] Fix viewbox_list https://github.com/alexandre01/deepsvg/issues/24 --- deepsvg/svglib/svg.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/deepsvg/svglib/svg.py b/deepsvg/svglib/svg.py index 637c2dc65..8cd23dcff 100644 --- a/deepsvg/svglib/svg.py +++ b/deepsvg/svglib/svg.py @@ -121,7 +121,13 @@ def from_str(svg_str: str): svg_dom = expatbuilder.parseString(svg_str, False) svg_root = svg_dom.getElementsByTagName('svg')[0] - viewbox_list = list(map(float, svg_root.getAttribute("viewBox").split(" "))) + viewbox_list = None + if svg_root.hasAttribute('viewBox'): + viewbox = list(map(float, svg_root.getAttribute("viewBox").split(" "))) + elif svg_root.hasAttribute('width') and svg_root.hasAttribute('height'): + viewbox_list = [0, 0, float(svg_root.getAttribute("width")), float(svg_root.getAttribute("height"))] + else: + raise Exception(' does not contain width, height attributes, nor viewBox. please double check the SVG') view_box = Bbox(*viewbox_list) primitives = {