From e1a9e7af852501e9fc4e66632671aed5fccb6001 Mon Sep 17 00:00:00 2001 From: Roberta Date: Wed, 12 May 2021 10:02:32 -0500 Subject: [PATCH 1/4] Change to python3 Just swapped python3 for python --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 09389b5..532618a 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: clean install install: - python setup.py install + python3 setup.py install clean: rm -rf build @@ -14,21 +14,21 @@ clean: find . -name "*__pycache__" -type d -prune -exec rm -rf {} \; publish: clean - python setup.py register - python setup.py sdist upload + python3 setup.py register + python3 setup.py sdist upload check: test flake8 test: - python test_scour.py + python3 test_scour.py test_version: - PYTHONPATH=. python -m scour.scour --version + PYTHONPATH=. python3 -m scour.scour --version test_help: - PYTHONPATH=. python -m scour.scour --help + PYTHONPATH=. python3 -m scour.scour --help flake8: flake8 --max-line-length=119 From 402c319275c67c64bd0be3c91cb93d011e1a2ce8 Mon Sep 17 00:00:00 2001 From: Roberta Date: Wed, 12 May 2021 10:11:55 -0500 Subject: [PATCH 2/4] Serialize data in animate values list Entire paths can be animated. That data now gets scoured. --- scour/scour.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scour/scour.py b/scour/scour.py index 91326c6..aed8b02 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -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): """ @@ -3803,7 +3815,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) From a1b72d564305cb0430e64dbac1168bf5751485b0 Mon Sep 17 00:00:00 2001 From: Roberta Date: Sat, 5 Jun 2021 09:02:52 -0500 Subject: [PATCH 3/4] revert to python python should be pointed to python3 in my os if I want/need to use it. --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 532618a..09389b5 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: clean install install: - python3 setup.py install + python setup.py install clean: rm -rf build @@ -14,21 +14,21 @@ clean: find . -name "*__pycache__" -type d -prune -exec rm -rf {} \; publish: clean - python3 setup.py register - python3 setup.py sdist upload + python setup.py register + python setup.py sdist upload check: test flake8 test: - python3 test_scour.py + python test_scour.py test_version: - PYTHONPATH=. python3 -m scour.scour --version + PYTHONPATH=. python -m scour.scour --version test_help: - PYTHONPATH=. python3 -m scour.scour --help + PYTHONPATH=. python -m scour.scour --help flake8: flake8 --max-line-length=119 From 03025e7fc239b3bc95fd7a8389e155d1584c611a Mon Sep 17 00:00:00 2001 From: Roberta Date: Sun, 13 Jun 2021 12:00:36 -0500 Subject: [PATCH 4/4] use join in clean animated path And test for empty values. --- scour/scour.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scour/scour.py b/scour/scour.py index aed8b02..ea9d3f9 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -2772,11 +2772,10 @@ def clean_animated_path(element, options, stats): 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 = "" - for oldPathStrPart in oldPathStrs: - path = svg_parser.parse(oldPathStrPart) - newPathStr += serializePath(path, options) + " ;\n" + newPathStr = ";".join(map(lambda s:serializePath(svg_parser.parse(s),options),oldPathStrs) element.setAttribute('values', newPathStr) def parseListOfPoints(s):