From 25ea02d31784fb847f2912947bfc64b1d9d29966 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Thu, 14 Feb 2019 21:13:51 +0100 Subject: [PATCH] Handle the drawing reaching into the negative x axis properly --- boxes/svgutil.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/boxes/svgutil.py b/boxes/svgutil.py index 528f02a..d253e77 100755 --- a/boxes/svgutil.py +++ b/boxes/svgutil.py @@ -95,8 +95,8 @@ class SVGFile(object): if m: f.seek(m.start(1)) - s = ('width="%imm" height="%imm" viewBox="0 %i %i %i"' % - (maxx - minx, maxy - miny, miny, maxx, maxy - miny)) + s = ('width="%imm" height="%imm" viewBox="%i %i %i %i"' % + (maxx - minx, maxy - miny, minx, miny, maxx - minx, maxy - miny)) if len(s) > len(m.group(1)): raise ValueError("Not enough space for size") @@ -115,11 +115,11 @@ unit2mm = {"mm" : 1.0, def getSizeInMM(tree): root = tree.getroot() - m = re.match(r"(\d+\.?\d*)(\D+)", root.get("height")) + m = re.match(r"(-?\d+\.?\d*)(\D+)", root.get("height")) height, units = m.groups() height = float(height) * unit2mm.get(units, 1.0) - m = re.match(r"(\d+\.?\d*)(\D+)", root.get("width")) + m = re.match(r"(-?\d+\.?\d*)(\D+)", root.get("width")) width, units = m.groups() width = float(width) * unit2mm.get(units, 1.0) @@ -127,10 +127,10 @@ def getSizeInMM(tree): def getViewBox(tree): root = tree.getroot() - m = re.match(r"\s*(\d+\.?\d*)\s+" - "(\d+\.?\d*)\s+" - "(\d+\.?\d*)\s+" - "(\d+\.?\d)\s*", root.get("viewBox")) + m = re.match(r"\s*(-?\d+\.?\d*)\s+" + "(-?\d+\.?\d*)\s+" + "(-?\d+\.?\d*)\s+" + "(-?\d+\.?\d)\s*", root.get("viewBox")) return [float(m) for m in m.groups()]