From 512bcc173784123253b760dbbc54adb4e95d5f49 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 19 Feb 2017 15:22:50 +0100 Subject: [PATCH] Reduce precision of lengths in viewBox This fixes #127. Also simplify splitting of viewBox lengths and avoiding a "FutureWarning: split() requires a non-empty pattern match" at the same time --- scour/scour.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scour/scour.py b/scour/scour.py index b4e848b..d3a3d71 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -3037,7 +3037,7 @@ def properlySizeDoc(docElement, options): # else we have a statically sized image and we should try to remedy that # parse viewBox attribute - vbSep = re.split("\\s*\\,?\\s*", docElement.getAttribute('viewBox'), 3) + vbSep = re.split('[, ]+', docElement.getAttribute('viewBox')) # if we have a valid viewBox we need to check it vbWidth, vbHeight = 0, 0 if len(vbSep) == 4: @@ -3471,6 +3471,11 @@ def scourString(in_string, options=None): 'x1', 'y1', 'x2', 'y2', 'fx', 'fy', 'offset']: if elem.getAttribute(attr) != '': elem.setAttribute(attr, scourLength(elem.getAttribute(attr))) + viewBox = doc.documentElement.getAttribute('viewBox') + if viewBox: + lengths = re.split('[, ]+', viewBox) + lengths = [scourUnitlessLength(lenght) for lenght in lengths] + doc.documentElement.setAttribute('viewBox', ' '.join(lengths)) # more length scouring in this function _num_bytes_saved_in_lengths = reducePrecision(doc.documentElement)