From 784b8efb2bf24467a438c6243297d4e4fbcb0d5b Mon Sep 17 00:00:00 2001 From: JSCHILL1 Date: Mon, 27 Apr 2009 11:43:11 -0500 Subject: [PATCH] Add path data bytes saved to report. Added input filename to report. Removed last of the useless files in fulltests. --- fulltests/README.fulltests.txt | 8 -------- fulltests/chained.svg | 8 -------- fulltests/units.svg | 6 ------ scour.py | 32 ++++++++++++++++++++++---------- unittests/path-precision.svg | 2 +- 5 files changed, 23 insertions(+), 33 deletions(-) delete mode 100644 fulltests/README.fulltests.txt delete mode 100644 fulltests/chained.svg delete mode 100644 fulltests/units.svg diff --git a/fulltests/README.fulltests.txt b/fulltests/README.fulltests.txt deleted file mode 100644 index 6229275..0000000 --- a/fulltests/README.fulltests.txt +++ /dev/null @@ -1,8 +0,0 @@ -The fulltests directory contains a variety of large SVG files that I've found in the wild (mostly from openclipart.org). - -I use these files as a sort of real world sanity test (by visualling comparing the scoured output with the original). - -When the unit tests build up to a respectable level this directory becomes less important in terms of verifying functionality but it will still help me retain a general sense of how well scour does its job in reducing filesize and complexity. - -Jeff Schiller -2009-04-22 \ No newline at end of file diff --git a/fulltests/chained.svg b/fulltests/chained.svg deleted file mode 100644 index 461d323..0000000 --- a/fulltests/chained.svg +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/fulltests/units.svg b/fulltests/units.svg deleted file mode 100644 index 5b23b23..0000000 --- a/fulltests/units.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/scour.py b/scour.py index 95ea13c..6f3ac76 100755 --- a/scour.py +++ b/scour.py @@ -192,6 +192,7 @@ numIDsRemoved = 0 numElemsRemoved = 0 numAttrsRemoved = 0 numRastersEmbedded = 0 +numBytesSavedInPathData = 0 # removes all unreferenced elements except for , , , , and # also vacuums the defs of any non-referenced renderable elements @@ -612,8 +613,11 @@ def repairStyle(node): # This method will do the following: # - parse the path data and reserialize def cleanPath(element) : + global numBytesSavedInPathData + # this gets the parser object from svg_regex.py - pathObj = svg_parser.parse(element.getAttribute('d')) + oldPathStr = element.getAttribute('d') + pathObj = svg_parser.parse(oldPathStr) # however, this parser object has some ugliness in it (lists of tuples of tuples of # numbers and booleans). we just need a list of (cmd,[numbers]): @@ -742,7 +746,10 @@ def cleanPath(element) : # TODO: collapse adjacent H or V segments that have coords in the same direction - element.setAttribute('d', serializePath(path)) + newPathStr = serializePath(path) + numBytesSavedInPathData += ( len(oldPathStr) - len(newPathStr) ) + element.setAttribute('d', newPathStr) + # - reserialize the path data with some cleanups: # - removes scientific notation (exponents) @@ -985,6 +992,7 @@ def parseCLA(): args = sys.argv[1:] # by default the input and output are the standard streams + inputfilename = '' input = sys.stdin output = sys.stdout options = [] @@ -999,6 +1007,7 @@ def parseCLA(): i += 1 if arg == '-i' : if i < len(args) : + inputfilename = args[i] input = open(args[i], 'r') i += 1 continue @@ -1017,11 +1026,11 @@ def parseCLA(): print 'Error! Invalid argument:', arg printSyntaxAndQuit() - return (input, output, options) + return (input, output, options, inputfilename) if __name__ == '__main__': - (input, output, options) = parseCLA() + (input, output, options, inputfilename) = parseCLA() # if we are not sending to stdout, then print out app information bOutputReport = False @@ -1040,12 +1049,15 @@ if __name__ == '__main__': # output some statistics if we are not using stdout if bOutputReport : - print " Number of unreferenced id attributes removed:", numIDsRemoved - print " Number of elements removed:", numElemsRemoved - print " Number of attributes removed:", numAttrsRemoved - print " Number of style properties fixed:", numStylePropsFixed - print " Number of raster images embedded inline:", numRastersEmbedded + if inputfilename != '': + print ' File:', inputfilename + print ' Number of unreferenced id attributes removed:', numIDsRemoved + print ' Number of elements removed:', numElemsRemoved + print ' Number of attributes removed:', numAttrsRemoved + print ' Number of style properties fixed:', numStylePropsFixed + print ' Number of raster images embedded inline:', numRastersEmbedded + print ' Number of bytes saved in path data:', numBytesSavedInPathData oldsize = os.path.getsize(input.name) newsize = os.path.getsize(output.name) sizediff = (newsize / oldsize); - print " Original file size:", oldsize, "bytes; new file size:", newsize, "bytes (" + str(sizediff)[:5] + "x)" + print ' Original file size:', oldsize, 'bytes; new file size:', newsize, 'bytes (' + str(sizediff)[:5] + 'x)' diff --git a/unittests/path-precision.svg b/unittests/path-precision.svg index 333fc16..1eb2bfe 100644 --- a/unittests/path-precision.svg +++ b/unittests/path-precision.svg @@ -1,3 +1,3 @@ - +