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:
parent
29fdd5ba66
commit
784b8efb2b
5 changed files with 23 additions and 33 deletions
|
|
@ -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
|
|
||||||
|
|
@ -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 |
|
|
@ -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 |
32
scour.py
32
scour.py
|
|
@ -192,6 +192,7 @@ numIDsRemoved = 0
|
||||||
numElemsRemoved = 0
|
numElemsRemoved = 0
|
||||||
numAttrsRemoved = 0
|
numAttrsRemoved = 0
|
||||||
numRastersEmbedded = 0
|
numRastersEmbedded = 0
|
||||||
|
numBytesSavedInPathData = 0
|
||||||
|
|
||||||
# removes all unreferenced elements except for <svg>, <font>, <metadata>, <title>, and <desc>
|
# removes all unreferenced elements except for <svg>, <font>, <metadata>, <title>, and <desc>
|
||||||
# also vacuums the defs of any non-referenced renderable elements
|
# also vacuums the defs of any non-referenced renderable elements
|
||||||
|
|
@ -612,8 +613,11 @@ def repairStyle(node):
|
||||||
# This method will do the following:
|
# This method will do the following:
|
||||||
# - parse the path data and reserialize
|
# - parse the path data and reserialize
|
||||||
def cleanPath(element) :
|
def cleanPath(element) :
|
||||||
|
global numBytesSavedInPathData
|
||||||
|
|
||||||
# this gets the parser object from svg_regex.py
|
# 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
|
# 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]):
|
# 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
|
# 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:
|
# - reserialize the path data with some cleanups:
|
||||||
# - removes scientific notation (exponents)
|
# - removes scientific notation (exponents)
|
||||||
|
|
@ -985,6 +992,7 @@ def parseCLA():
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
|
|
||||||
# by default the input and output are the standard streams
|
# by default the input and output are the standard streams
|
||||||
|
inputfilename = ''
|
||||||
input = sys.stdin
|
input = sys.stdin
|
||||||
output = sys.stdout
|
output = sys.stdout
|
||||||
options = []
|
options = []
|
||||||
|
|
@ -999,6 +1007,7 @@ def parseCLA():
|
||||||
i += 1
|
i += 1
|
||||||
if arg == '-i' :
|
if arg == '-i' :
|
||||||
if i < len(args) :
|
if i < len(args) :
|
||||||
|
inputfilename = args[i]
|
||||||
input = open(args[i], 'r')
|
input = open(args[i], 'r')
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
|
@ -1017,11 +1026,11 @@ def parseCLA():
|
||||||
print 'Error! Invalid argument:', arg
|
print 'Error! Invalid argument:', arg
|
||||||
printSyntaxAndQuit()
|
printSyntaxAndQuit()
|
||||||
|
|
||||||
return (input, output, options)
|
return (input, output, options, inputfilename)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
(input, output, options) = parseCLA()
|
(input, output, options, inputfilename) = parseCLA()
|
||||||
|
|
||||||
# if we are not sending to stdout, then print out app information
|
# if we are not sending to stdout, then print out app information
|
||||||
bOutputReport = False
|
bOutputReport = False
|
||||||
|
|
@ -1040,12 +1049,15 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
# output some statistics if we are not using stdout
|
# output some statistics if we are not using stdout
|
||||||
if bOutputReport :
|
if bOutputReport :
|
||||||
print " Number of unreferenced id attributes removed:", numIDsRemoved
|
if inputfilename != '':
|
||||||
print " Number of elements removed:", numElemsRemoved
|
print ' File:', inputfilename
|
||||||
print " Number of attributes removed:", numAttrsRemoved
|
print ' Number of unreferenced id attributes removed:', numIDsRemoved
|
||||||
print " Number of style properties fixed:", numStylePropsFixed
|
print ' Number of elements removed:', numElemsRemoved
|
||||||
print " Number of raster images embedded inline:", numRastersEmbedded
|
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)
|
oldsize = os.path.getsize(input.name)
|
||||||
newsize = os.path.getsize(output.name)
|
newsize = os.path.getsize(output.name)
|
||||||
sizediff = (newsize / oldsize);
|
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)'
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
<svg viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg" version="1.1">
|
<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>
|
</svg>
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 157 B After Width: | Height: | Size: 173 B |
Loading…
Add table
Add a link
Reference in a new issue