From 46f86a097874441ff7b6e84a465a5b467b46cbac Mon Sep 17 00:00:00 2001 From: JSCHILL1 Date: Sat, 1 Aug 2009 11:59:54 -0500 Subject: [PATCH] Prevent scour from trying to remove a duplicate gradient more than once --- package.sh | 2 +- scour.py | 7 +++++-- testscour.py | 2 ++ unittests/remove-duplicate-gradients.svg | 5 +++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/package.sh b/package.sh index 3eae3b6..ae1fec5 100755 --- a/package.sh +++ b/package.sh @@ -1,5 +1,5 @@ #!/bin/bash -SCOURVER="0.16" +SCOURVER="0.17" cd .. tar cvf scour/tarballs/scour-$SCOURVER.tar scour/scour.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html gzip scour/tarballs/scour-$SCOURVER.tar diff --git a/scour.py b/scour.py index 6b21416..96157b9 100755 --- a/scour.py +++ b/scour.py @@ -743,22 +743,25 @@ def removeDuplicateGradients(doc): if stopsNotEqual: continue # ograd is a duplicate of grad, we schedule it to be removed UNLESS - # ograd is ALREADY considered the 'master' element + # ograd is ALREADY considered a 'master' element if not gradientsToRemove.has_key(ograd): if not gradientsToRemove.has_key(grad): gradientsToRemove[grad] = [] gradientsToRemove[grad].append( ograd ) + # get a collection of all elements that are referenced and their referencing elements referencedIDs = findReferencedElements(doc.documentElement) for masterGrad in gradientsToRemove.keys(): master_id = masterGrad.getAttribute('id') for dupGrad in gradientsToRemove[masterGrad]: + # if the duplicate gradient no longer has a parent that means it was + # already re-mapped to another master gradient + if not dupGrad.parentNode: continue dup_id = dupGrad.getAttribute('id') # for each element that referenced the gradient we are going to remove for elem in referencedIDs[dup_id][1]: # find out which attribute referenced the duplicate gradient for attr in ['fill', 'stroke']: - # TODO: also need to check for url("#id") v = elem.getAttribute(attr) if v == 'url(#'+dup_id+')' or v == 'url("#'+dup_id+'")' or v == "url('#"+dup_id+"')": elem.setAttribute(attr, 'url(#'+master_id+')') diff --git a/testscour.py b/testscour.py index 3dbeac0..5a06e4f 100755 --- a/testscour.py +++ b/testscour.py @@ -677,6 +677,8 @@ class RereferenceForLinearGradient(unittest.TestCase): rects = svgdoc.getElementsByTagNameNS(SVGNS, 'rect') self.assertEquals(rects[0].getAttribute('fill'), rects[1].getAttribute('stroke'), 'Rect not changed after removing duplicate linear gradient') + self.assertEquals(rects[0].getAttribute('fill'), rects[4].getAttribute('fill'), + 'Rect not changed after removing duplicate linear gradient') class RemoveDuplicateRadialGradients(unittest.TestCase): def runTest(self): diff --git a/unittests/remove-duplicate-gradients.svg b/unittests/remove-duplicate-gradients.svg index 536344a..f986bdd 100644 --- a/unittests/remove-duplicate-gradients.svg +++ b/unittests/remove-duplicate-gradients.svg @@ -10,9 +10,14 @@ + + + + +