This commit is contained in:
Roberta 2021-09-02 04:13:11 -04:00 committed by GitHub
commit d6d0c29aff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2766,6 +2766,17 @@ def clean_path(element, options, stats):
stats.num_bytes_saved_in_path_data += (len(oldPathStr) - len(newPathStr))
element.setAttribute('d', newPathStr)
def clean_animated_path(element, options, stats):
"""
Cleans (precision only) the path strings (values that will replace a path's d attribute) of the animation element
These are ';' delimited path data that must keep the same number of nodes, so the only cleaning is via serializePath
"""
oldPathStr = element.getAttribute('values')
if oldPathStr=="":
return
oldPathStrs = oldPathStr.split(';')
newPathStr = ";".join(map(lambda s:serializePath(svg_parser.parse(s),options),oldPathStrs)
element.setAttribute('values', newPathStr)
def parseListOfPoints(s):
"""
@ -3803,7 +3814,12 @@ def scourString(in_string, options=None, stats=None):
elem.parentNode.removeChild(elem)
else:
clean_path(elem, options, stats)
# clean path based animation data
for elem in doc.documentElement.getElementsByTagName('animate'):
if elem.getAttribute('attributeName') == 'd':
clean_animated_path(elem, options, stats)
# shorten ID names as much as possible
if options.shorten_ids:
stats.num_bytes_saved_in_ids += shortenIDs(doc, options.shorten_ids_prefix, options)