Fix replacement of duplicate gradients if "fill/stroke" contains fallbacks (#109)
(fixes #79)
This commit is contained in:
parent
564367f886
commit
ec855211de
4 changed files with 30 additions and 14 deletions
|
|
@ -1381,22 +1381,27 @@ def removeDuplicateGradients(doc):
|
|||
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
|
||||
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')
|
||||
# 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]:
|
||||
# find out which attribute referenced the duplicate gradient
|
||||
for attr in ['fill', 'stroke']:
|
||||
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+')')
|
||||
(v_new, n) = funcIRI.subn('url(#'+master_id+')', v)
|
||||
if n > 0:
|
||||
elem.setAttribute(attr, v_new)
|
||||
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+')'
|
||||
(v_new, n) = funcIRI.subn('url(#'+master_id+')', v)
|
||||
if n > 0:
|
||||
styles[style] = v_new
|
||||
_setStyle(elem, styles)
|
||||
|
||||
# now that all referencing elements have been re-mapped to the master
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue