Fix Bug 734933: Do not remove empty path segments if stroke-linecap is round

This commit is contained in:
Jeff Schiller 2011-03-15 08:16:16 -07:00
parent cd42752cad
commit 6c50c78d99
3 changed files with 61 additions and 44 deletions

View file

@ -1709,6 +1709,10 @@ def cleanPath(element, options) :
oldPathStr = element.getAttribute('d')
path = svg_parser.parse(oldPathStr)
# This determines whether the stroke has round linecaps. If it does,
# we do not want to collapse empty segments, as they are actually rendered.
withRoundLineCaps = element.getAttribute('stroke-linecap') == 'round'
# The first command must be a moveto, and whether it's relative (m)
# or absolute (M), the first set of coordinates *is* absolute. So
# the first iteration of the loop below will get x,y and startx,starty.
@ -1817,6 +1821,7 @@ def cleanPath(element, options) :
# remove empty segments
# Reuse the data structure 'path' and the coordinate lists, even if we're
# deleting items, because these deletions are relatively cheap.
if not withRoundLineCaps:
for pathIndex in xrange(0, len(path)):
cmd, data = path[pathIndex]
i = 0

View file

@ -544,6 +544,14 @@ class RemoveEmptyLineSegmentsFromPath(unittest.TestCase):
self.assertEquals(path[4][0], 'z',
'Did not remove an empty line segment from path' )
# Do not remove empty segments if round linecaps.
class DoNotRemoveEmptySegmentsFromPathWithRoundLineCaps(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/path-with-caps.svg')
path = svg_parser.parse(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('d'))
self.assertEquals(len(path), 2,
'Did not preserve empty segments when path had round linecaps' )
class ChangeLineToHorizontalLineSegmentInPath(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/path-line-optimize.svg')

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg">
<path fill="none" stroke="#000" stroke-width="5" stroke-linecap="round" d="m 11,8 0,0" />
</svg>

After

Width:  |  Height:  |  Size: 195 B