Don't force whitespace for elliptical paths (fixes #89)

This was only required in an early draft of the SVG spec (an error that was corrected later, see [1,2])

[1] https://github.com/scour-project/scour/issues/89#issuecomment-244216600
[2] https://github.com/scour-project/scour/issues/89#issuecomment-244337118
This commit is contained in:
Eduard Braun 2017-02-24 03:04:15 +01:00
parent 7dcdc2b00b
commit d853548c57
3 changed files with 3 additions and 16 deletions

View file

@ -2539,7 +2539,7 @@ def serializePath(pathObj, options):
"""
# elliptical arc commands must have comma/wsp separating the coordinates
# this fixes an issue outlined in Fix https://bugs.launchpad.net/scour/+bug/412754
return ''.join([cmd + scourCoordinates(data, options, (cmd == 'a'), cmd) for cmd, data in pathObj])
return ''.join([cmd + scourCoordinates(data, options, path_cmd=cmd) for cmd, data in pathObj])
def serializeTransform(transformObj):
@ -2554,7 +2554,7 @@ def serializeTransform(transformObj):
)
def scourCoordinates(data, options, force_whitespace=False, cmd=''):
def scourCoordinates(data, options, force_whitespace=False, path_cmd=''):
"""
Serializes coordinate data with some cleanups:
- removes all trailing zeros after the decimal
@ -2567,7 +2567,7 @@ def scourCoordinates(data, options, force_whitespace=False, cmd=''):
c = 0
previousCoord = ''
for coord in data:
cp = ((cmd == 'c' and (c % 6) < 4) or (cmd == 's' and (c % 4) < 2))
cp = ((path_cmd == 'c' and (c % 6) < 4) or (path_cmd == 's' and (c % 4) < 2))
scouredCoord = scourUnitlessLength(coord,
needsRendererWorkaround=options.renderer_workaround,
isControlPoint=cp)

View file

@ -1640,15 +1640,6 @@ class PropagateCommonAttributesUp(unittest.TestCase):
'Did not move common fill attribute to grandparent')
class PathEllipticalArcParsingCommaWsp(unittest.TestCase):
def runTest(self):
p = scourXmlFile('unittests/path-elliptical-arc-parsing.svg') \
.getElementsByTagNameNS(SVGNS, 'path')[0]
self.assertEqual(p.getAttribute('d'), 'm100 100a100 100 0 1 1 -50 100z',
'Did not parse elliptical arc command properly')
class RemoveUnusedAttributesOnParent(unittest.TestCase):
def runTest(self):

View file

@ -1,4 +0,0 @@
<?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>

Before

Width:  |  Height:  |  Size: 175 B