From 437dbf991c52518215ae516b0a31ea06ed1df825 Mon Sep 17 00:00:00 2001 From: Louis Simard Date: Sat, 12 Mar 2011 03:22:03 -0500 Subject: [PATCH] Fix bug 702423, "Scour corrupts icons with gradients when --disable-style-to-xml is used". Add 2 more full tests gathered from the bug reports, as well as 1 more unit test. --- fulltests/deja-dup.svg | 207 +++++++++++++++ fulltests/go-bottom.svg | 249 ++++++++++++++++++ scour.py | 6 + testscour.py | 12 + .../duplicate-gradients-update-style.svg | 15 ++ 5 files changed, 489 insertions(+) create mode 100644 fulltests/deja-dup.svg create mode 100644 fulltests/go-bottom.svg create mode 100644 unittests/duplicate-gradients-update-style.svg diff --git a/fulltests/deja-dup.svg b/fulltests/deja-dup.svg new file mode 100644 index 0000000..ca3506c --- /dev/null +++ b/fulltests/deja-dup.svg @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + Déjà Dup + + + reload + refresh + view + + + + + Michael Terry + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fulltests/go-bottom.svg b/fulltests/go-bottom.svg new file mode 100644 index 0000000..263df90 --- /dev/null +++ b/fulltests/go-bottom.svg @@ -0,0 +1,249 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scour.py b/scour.py index 4d75408..c1a1ace 100755 --- a/scour.py +++ b/scour.py @@ -1291,6 +1291,12 @@ def removeDuplicateGradients(doc): elem.setAttribute(attr, 'url(#'+master_id+')') if elem.getAttributeNS(NS['XLINK'], 'href') == '#'+dup_id: elem.setAttributeNS(NS['XLINK'], 'href', '#'+master_id) + styles = _getStyle(elem) + for style in styles: + v = styles[style] + if v == 'url(#'+dup_id+')' or v == 'url("#'+dup_id+'")' or v == "url('#"+dup_id+"')": + styles[style] = 'url(#'+master_id+')' + _setStyle(elem, styles) # now that all referencing elements have been re-mapped to the master # it is safe to remove this gradient from the document diff --git a/testscour.py b/testscour.py index a4d0d2d..82f1ab3 100755 --- a/testscour.py +++ b/testscour.py @@ -1217,6 +1217,18 @@ class RemoveDefsWithWhitespace(unittest.TestCase): self.assertEquals(doc.getElementsByTagName('defs').length, 0, 'Kept defs, although it contains only whitespace or is ') +class DuplicateGradientsUpdateStyle(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/duplicate-gradients-update-style.svg', + scour.parse_args(['--disable-style-to-xml'])[0]) + gradientTag = doc.getElementsByTagName('linearGradient')[0] + rectTag0 = doc.getElementsByTagName('rect')[0] + rectTag1 = doc.getElementsByTagName('rect')[1] + self.assertEquals('fill:url(#' + gradientTag.getAttribute('id') + ')', rectTag0.getAttribute('style'), + 'Either of #duplicate-one or #duplicate-two was removed, but style="fill:" was not updated to reflect this') + self.assertEquals('fill:url(#' + gradientTag.getAttribute('id') + ')', rectTag1.getAttribute('style'), + 'Either of #duplicate-one or #duplicate-two was removed, but style="fill:" was not updated to reflect this') + # TODO: write tests for --enable-viewboxing # TODO; write a test for embedding rasters # TODO: write a test for --disable-embed-rasters diff --git a/unittests/duplicate-gradients-update-style.svg b/unittests/duplicate-gradients-update-style.svg new file mode 100644 index 0000000..c28070c --- /dev/null +++ b/unittests/duplicate-gradients-update-style.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file