Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scour animated paths #280

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion scour/scour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(';')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
oldPathStrs = oldPathStr.split(';')
if oldPathStr == '':
return
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):
"""
Expand Down Expand Up @@ -3803,7 +3815,12 @@ def xmlnsUnused(prefix, namespace):
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)
Expand Down