Prevent scour from trying to remove a duplicate gradient more than once
This commit is contained in:
parent
b119af0499
commit
46f86a0978
4 changed files with 13 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
7
scour.py
7
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+')')
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -10,9 +10,14 @@
|
|||
</linearGradient>
|
||||
<radialGradient xlink:href="#g1" id="g3" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1, 0, 0, 0.481529, -718.417, 98.7046)" cx="323.75433" cy="209.73672" fx="323.75433" fy="209.73672" r="6.2794499"/>
|
||||
<radialGradient xlink:href="#g2" id="g4" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1, 0, 0, 0.481529, -718.417, 98.7046)" cx="323.75433" cy="209.73672" fx="323.75433" fy="209.73672" r="6.2794499"/>
|
||||
<linearGradient id='g5' x1='0' y1='0' x2='1' y2='1'>
|
||||
<stop offset='0' stop-color='red'/>
|
||||
<stop offset='1' stop-color='blue'/>
|
||||
</linearGradient>
|
||||
|
||||
<rect id="r1" fill="url(#g1)" width="100" height="100"/>
|
||||
<rect id="r2" stroke="url('#g2')" width="100" height="100"/>
|
||||
<rect id="r3" stroke="url(#g3)" width="100" height="100"/>
|
||||
<rect id="r4" fill='url("#g4")' width="100" height="100"/>
|
||||
<rect id="r5" fill="url(#g5)" width="100" height="100"/>
|
||||
</svg>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.3 KiB |
Loading…
Add table
Add a link
Reference in a new issue