From cf5fb8a37d345dd1e265d3bb7b4a05909415f446 Mon Sep 17 00:00:00 2001 From: JSCHILL1 Date: Wed, 12 Aug 2009 23:41:09 -0500 Subject: [PATCH] Fix Bug 412754: Elliptical arc commands must have comma or whitespace separating --- scour.py | 12 +++++++----- testscour.py | 6 ++++++ unittests/path-elliptical-arc-parsing.svg | 4 ++++ 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 unittests/path-elliptical-arc-parsing.svg diff --git a/scour.py b/scour.py index 50a5aa4..091249d 100755 --- a/scour.py +++ b/scour.py @@ -1759,16 +1759,18 @@ def serializePath(pathObj): pathStr = "" for (cmd,data) in pathObj: pathStr += cmd - pathStr += scourCoordinates(data) + # elliptical arc commands must have comma/wsp separating the coordinates + # this fixes an issue outlined in Fix https://bugs.launchpad.net/scour/+bug/412754 + pathStr += scourCoordinates(data, (cmd == 'a')) return pathStr -def scourCoordinates(data): +def scourCoordinates(data, forceCommaWsp = False): """ Serializes coordinate data with some cleanups: - removes all trailing zeros after the decimal - integerize coordinates if possible - removes extraneous whitespace - - adds commas between values in a subcommand if required + - adds commas between values in a subcommand if required (or if forceCommaWsp is True) """ coordsStr = "" if data != None: @@ -1777,8 +1779,8 @@ def scourCoordinates(data): # add the scoured coordinate to the path string coordsStr += scourLength(coord) - # only need the comma if the next number is non-negative - if c < len(data)-1 and Decimal(data[c+1]) >= 0: + # only need the comma if the next number is non-negative or if forceCommaWsp is True + if c < len(data)-1 and (forceCommaWsp or Decimal(data[c+1]) >= 0): coordsStr += ',' c += 1 return coordsStr diff --git a/testscour.py b/testscour.py index f284435..3fbd91d 100755 --- a/testscour.py +++ b/testscour.py @@ -892,6 +892,12 @@ class PropagateCommonAttributesUp(unittest.TestCase): g = scour.scourXmlFile('unittests/move-common-attributes-to-grandparent.svg').getElementsByTagNameNS(SVGNS, 'g')[0] self.assertEquals( g.getAttribute('fill'), '#0F0', 'Did not move common fill attribute to grandparent') + +class PathEllipticalArcParsingCommaWsp(unittest.TestCase): + def runTest(self): + p = scour.scourXmlFile('unittests/path-elliptical-arc-parsing.svg').getElementsByTagNameNS(SVGNS, 'path')[0] + self.assertEquals( p.getAttribute('d'), 'M100,100a100,100,0,1,1,-50,100z', + 'Did not parse elliptical arc command properly') # TODO; write a test for embedding rasters # TODO: write a test for --disable-embed-rasters diff --git a/unittests/path-elliptical-arc-parsing.svg b/unittests/path-elliptical-arc-parsing.svg new file mode 100644 index 0000000..77a8cbd --- /dev/null +++ b/unittests/path-elliptical-arc-parsing.svg @@ -0,0 +1,4 @@ + + + +