Collect globals for tracking statistics in scourString() and make sure they're all properly initialized to zero.

Before statistics were wrong when scouring multiple files/strings because initialization was only done once when loading the module.
This commit is contained in:
Eduard Braun 2016-09-18 15:47:07 +02:00
parent 4410f91dad
commit 47bc477cd1

View file

@ -534,8 +534,8 @@ def findElementsWithId(node, elems=None):
findElementsWithId(child, elems) findElementsWithId(child, elems)
return elems return elems
referencingProps = ['fill', 'stroke', 'filter', 'clip-path', 'mask', 'marker-start',
'marker-end', 'marker-mid'] referencingProps = ['fill', 'stroke', 'filter', 'clip-path', 'mask', 'marker-start', 'marker-end', 'marker-mid']
def findReferencedElements(node, ids=None): def findReferencedElements(node, ids=None):
@ -625,20 +625,6 @@ def findReferencingProperty(node, prop, val, ids):
else: else:
ids[id] = [1, [node]] ids[id] = [1, [node]]
numIDsRemoved = 0
numElemsRemoved = 0
numAttrsRemoved = 0
numRastersEmbedded = 0
numPathSegmentsReduced = 0
numCurvesStraightened = 0
numBytesSavedInPathData = 0
numBytesSavedInColors = 0
numBytesSavedInIDs = 0
numBytesSavedInLengths = 0
numBytesSavedInTransforms = 0
numPointsRemovedFromPolygon = 0
numCommentBytes = 0
def removeUnusedDefs(doc, defElem, elemsToRemove=None): def removeUnusedDefs(doc, defElem, elemsToRemove=None):
if elemsToRemove is None: if elemsToRemove is None:
@ -2053,7 +2039,6 @@ def cleanPath(element, options):
""" """
global numBytesSavedInPathData global numBytesSavedInPathData
global numPathSegmentsReduced global numPathSegmentsReduced
global numCurvesStraightened
# this gets the parser object from svg_regex.py # this gets the parser object from svg_regex.py
oldPathStr = element.getAttribute('d') oldPathStr = element.getAttribute('d')
@ -2254,7 +2239,6 @@ def cleanPath(element, options):
newData = [] newData = []
# now create a straight line segment # now create a straight line segment
newPath.append(('l', [dx, dy])) newPath.append(('l', [dx, dy]))
numCurvesStraightened += 1
else: else:
newData.extend(data[i:i + 6]) newData.extend(data[i:i + 6])
@ -3253,14 +3237,37 @@ def scourString(in_string, options=None):
global scouringContext global scouringContext
scouringContext = Context(prec=options.digits) scouringContext = Context(prec=options.digits)
global numAttrsRemoved # globals for tracking statistics
global numStylePropsFixed # TODO: get rid of these globals...
global numElemsRemoved global numElemsRemoved
global numBytesSavedInColors global numAttrsRemoved
global numIDsRemoved
global numCommentsRemoved global numCommentsRemoved
global numStylePropsFixed
global numRastersEmbedded
global numPathSegmentsReduced
global numBytesSavedInPathData
global numBytesSavedInColors
global numPointsRemovedFromPolygon
global numCommentBytes
global numBytesSavedInIDs global numBytesSavedInIDs
global numBytesSavedInLengths global numBytesSavedInLengths
global numBytesSavedInTransforms global numBytesSavedInTransforms
numElemsRemoved = 0
numAttrsRemoved = 0
numIDsRemoved = 0
numCommentsRemoved = 0
numStylePropsFixed = 0
numRastersEmbedded = 0
numPathSegmentsReduced = 0
numBytesSavedInPathData = 0
numBytesSavedInColors = 0
numPointsRemovedFromPolygon = 0
numCommentBytes = 0
numBytesSavedInIDs = 0
numBytesSavedInLengths = 0
numBytesSavedInTransforms = 0
doc = xml.dom.minidom.parseString(in_string) doc = xml.dom.minidom.parseString(in_string)
# determine number of flowRoot elements in input document # determine number of flowRoot elements in input document