Add path data bytes saved to report. Added input filename to report. Removed last of the useless files in fulltests.

This commit is contained in:
JSCHILL1 2009-04-27 11:43:11 -05:00
parent 29fdd5ba66
commit 784b8efb2b
5 changed files with 23 additions and 33 deletions

View file

@ -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

View file

@ -1,8 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient id="g1" />
<linearGradient id="g2" xlink:href="#g1" />
<linearGradient id="g3" xlink:href="#g2" />
</defs>
<circle cx="50" cy="50" r="20" fill='blue' />
</svg>

Before

Width:  |  Height:  |  Size: 274 B

View file

@ -1,6 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="400px" height="300px">
<rect width="200" height="100" fill="blue" style="stroke-width:1px" />
<rect width="200" height="100" fill="blue" style="stroke-width:100.00e-2pt" />
<rect width="200" height="100" fill="blue" style="stroke-width:-0.000000000006e+14em" />
<rect width="200" height="100" fill="blue" style="stroke-width:4%" />
</svg>

Before

Width:  |  Height:  |  Size: 393 B

View file

@ -192,6 +192,7 @@ numIDsRemoved = 0
numElemsRemoved = 0
numAttrsRemoved = 0
numRastersEmbedded = 0
numBytesSavedInPathData = 0
# removes all unreferenced elements except for <svg>, <font>, <metadata>, <title>, and <desc>
# 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)'

View file

@ -1,3 +1,3 @@
<svg viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg" version="1.1">
<path d="M 100.0000001 99.9999999 h100.001 v100 h-100 z" fill="red" />
<path d="M 100.0000001 99.9999999 h100.001 v123456789.123456789 h-100 z" fill="red" />
</svg>

Before

Width:  |  Height:  |  Size: 157 B

After

Width:  |  Height:  |  Size: 173 B

Before After
Before After