From 9042bbae31fbf46fbf37e34626e6b00683f189e7 Mon Sep 17 00:00:00 2001 From: JSCHILL1 Date: Sat, 27 Mar 2010 11:41:19 -0500 Subject: [PATCH] Fix Bug 519698: Do not collapse move commands together because they may have line segments --- release-notes.html | 11 +++++++++++ scour.py | 14 ++++++-------- testscour.py | 6 ++++++ unittests/path-implicit-line.svg | 4 ++++ 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 unittests/path-implicit-line.svg diff --git a/release-notes.html b/release-notes.html index d62af29..c2284c0 100644 --- a/release-notes.html +++ b/release-notes.html @@ -9,6 +9,17 @@

Copyright 2010, Jeff Schiller

+
+
+

Version 0.25

+
+

2010-03-25

+ +
+

Version 0.24

diff --git a/scour.py b/scour.py index 60d0311..94088fd 100755 --- a/scour.py +++ b/scour.py @@ -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] + '%)' - - diff --git a/testscour.py b/testscour.py index a1a1105..c2f8969 100755 --- a/testscour.py +++ b/testscour.py @@ -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 diff --git a/unittests/path-implicit-line.svg b/unittests/path-implicit-line.svg new file mode 100644 index 0000000..ecbbe9a --- /dev/null +++ b/unittests/path-implicit-line.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file