Fix replacement of duplicate gradients if "fill/stroke" contains fallbacks.
(fixes #79)
This commit is contained in:
parent
564367f886
commit
9dd0d2ab49
1 changed files with 11 additions and 6 deletions
|
|
@ -1381,22 +1381,27 @@ def removeDuplicateGradients(doc):
|
||||||
for dupGrad in gradientsToRemove[masterGrad]:
|
for dupGrad in gradientsToRemove[masterGrad]:
|
||||||
# if the duplicate gradient no longer has a parent that means it was
|
# if the duplicate gradient no longer has a parent that means it was
|
||||||
# already re-mapped to another master gradient
|
# already re-mapped to another master gradient
|
||||||
if not dupGrad.parentNode: continue
|
if not dupGrad.parentNode:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# for each element that referenced the gradient we are going to replace dup_id with master_id
|
||||||
dup_id = dupGrad.getAttribute('id')
|
dup_id = dupGrad.getAttribute('id')
|
||||||
# for each element that referenced the gradient we are going to remove
|
funcIRI = re.compile('url\([\'"]?#' + dup_id + '[\'"]?\)') # matches url(#a), url('#a') and url("#a")
|
||||||
for elem in referencedIDs[dup_id][1]:
|
for elem in referencedIDs[dup_id][1]:
|
||||||
# find out which attribute referenced the duplicate gradient
|
# find out which attribute referenced the duplicate gradient
|
||||||
for attr in ['fill', 'stroke']:
|
for attr in ['fill', 'stroke']:
|
||||||
v = elem.getAttribute(attr)
|
v = elem.getAttribute(attr)
|
||||||
if v == 'url(#'+dup_id+')' or v == 'url("#'+dup_id+'")' or v == "url('#"+dup_id+"')":
|
(v_new, n) = funcIRI.subn('url(#'+master_id+')', v)
|
||||||
elem.setAttribute(attr, 'url(#'+master_id+')')
|
if n > 0:
|
||||||
|
elem.setAttribute(attr, v_new)
|
||||||
if elem.getAttributeNS(NS['XLINK'], 'href') == '#'+dup_id:
|
if elem.getAttributeNS(NS['XLINK'], 'href') == '#'+dup_id:
|
||||||
elem.setAttributeNS(NS['XLINK'], 'href', '#'+master_id)
|
elem.setAttributeNS(NS['XLINK'], 'href', '#'+master_id)
|
||||||
styles = _getStyle(elem)
|
styles = _getStyle(elem)
|
||||||
for style in styles:
|
for style in styles:
|
||||||
v = styles[style]
|
v = styles[style]
|
||||||
if v == 'url(#'+dup_id+')' or v == 'url("#'+dup_id+'")' or v == "url('#"+dup_id+"')":
|
(v_new, n) = funcIRI.subn('url(#'+master_id+')', v)
|
||||||
styles[style] = 'url(#'+master_id+')'
|
if n > 0:
|
||||||
|
styles[style] = v_new
|
||||||
_setStyle(elem, styles)
|
_setStyle(elem, styles)
|
||||||
|
|
||||||
# now that all referencing elements have been re-mapped to the master
|
# now that all referencing elements have been re-mapped to the master
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue