Fix Bug 519698: Do not collapse move commands together because they may have line segments

This commit is contained in:
JSCHILL1 2010-03-27 11:41:19 -05:00
parent 05e73f11c3
commit 9042bbae31
4 changed files with 27 additions and 8 deletions

View file

@ -9,6 +9,17 @@
<p>Copyright 2010, Jeff Schiller</p>
<section id="0.25">
<header>
<h2><a href="#0.25">Version 0.25</a></h2>
</header>
<p>2010-03-25</p>
<ul>
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/541889">Bug 541889</a> to parse polygon/polyline points missing whitespace/comma separating a negative value. Always output points attributes as comma-separated.</li>
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/519698">Bug 519698</a> to properly parse move commands that have line segments.</li>
</ul>
</section>
<section id="0.24">
<header>
<h2><a href="#0.24">Version 0.24</a></h2>

View file

@ -34,7 +34,6 @@
# at rounded corners)
# Next Up:
# - Bug 511186: option to keep XML comments between prolog and root element
# - only remove unreferenced elements if they are not children of a referenced element
# - add an option to remove ids if they match the Inkscape-style of IDs
# - investigate point-reducing algorithms
@ -1355,7 +1354,7 @@ def cleanPath(element) :
else:
# we have a move and then 1 or more coords for lines
N = len(path[0][1])
if path[0] == 'M':
if path[0][0] == 'M':
# take the last pair of coordinates for the starting point
x = path[0][1][N-2]
y = path[0][1][N-1]
@ -1624,13 +1623,14 @@ def cleanPath(element) :
for (cmd,data) in path[1:]:
# flush the previous command if it is not the same type as the current command
if prevCmd != '':
if cmd != prevCmd:
if cmd != prevCmd or cmd == 'm':
newPath.append( (prevCmd, prevData) )
prevCmd = ''
prevData = []
# if the previous and current commands are the same type, collapse
if cmd == prevCmd:
# but only if they are not move commands (since move can contain implicit lineto commands)
if cmd == prevCmd and cmd != 'm':
for coord in data:
prevData.append(coord)
@ -1757,13 +1757,13 @@ def cleanPath(element) :
for (cmd,data) in path[1:]:
# flush the previous command if it is not the same type as the current command
if prevCmd != '':
if cmd != prevCmd:
if cmd != prevCmd or cmd == 'm':
newPath.append( (prevCmd, prevData) )
prevCmd = ''
prevData = []
# if the previous and current commands are the same type, collapse
if cmd == prevCmd:
if cmd == prevCmd and cmd != 'm':
for coord in data:
prevData.append(coord)
@ -2480,5 +2480,3 @@ if __name__ == '__main__':
sizediff = (newsize / oldsize) * 100
print >>sys.stderr, ' Original file size:', oldsize, 'bytes;', \
'new file size:', newsize, 'bytes (' + str(sizediff)[:5] + '%)'

View file

@ -1019,6 +1019,12 @@ class DoNotStripDoctype(unittest.TestCase):
self.assertEquals( doc.childNodes[1].nodeType, 10, 'Second node not a doctype')
self.assertEquals( doc.childNodes[2].nodeType, 1, 'Third node not the root node')
class PathImplicitLineWithMoveCommands(unittest.TestCase):
def runTest(self):
path = scour.scourXmlFile('unittests/path-implicit-line.svg').getElementsByTagNameNS(SVGNS, 'path')[0]
self.assertEquals( path.getAttribute('d'), "M100,100,100,200m200-100-200,0m200,100,0-100",
"Implicit line segments after move not preserved")
# TODO: write tests for --enable-viewboxing
# 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">
<path stroke="#000" d="M100,100,100,200 M300,100,100,100 M300,200,300,100" fill="none"/>
</svg>

After

Width:  |  Height:  |  Size: 192 B