Fix Bug 412754: Elliptical arc commands must have comma or whitespace separating

This commit is contained in:
JSCHILL1 2009-08-12 23:41:09 -05:00
parent d519dae9db
commit cf5fb8a37d
3 changed files with 17 additions and 5 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<path d="M100,100a100,100,0,1,1,-50,100z" fill="red" />
</svg>

After

Width:  |  Height:  |  Size: 175 B