Serialize data in animate values list

Entire paths can be animated. That data now gets scoured.
This commit is contained in:
Roberta 2021-05-12 10:11:55 -05:00 committed by GitHub
parent e1a9e7af85
commit 402c319275
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2766,6 +2766,18 @@ 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')
oldPathStrs = oldPathStr.split(';')
newPathStr = ""
for oldPathStrPart in oldPathStrs:
path = svg_parser.parse(oldPathStrPart)
newPathStr += serializePath(path, options) + " ;\n"
element.setAttribute('values', newPathStr)
def parseListOfPoints(s):
"""
@ -3804,6 +3816,11 @@ def scourString(in_string, options=None, stats=None):
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)