Preserve xhref:href attr when collapsing referenced gradients

Closes: #198
Closes: #202
Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
Niels Thykier 2018-08-18 15:18:18 +00:00 committed by Patrick Storz
parent f61b4d36d6
commit 6846e0c9ee

View file

@ -1338,8 +1338,16 @@ def collapseSinglyReferencedGradients(doc):
if refElem.getAttribute(attr) == '' and not elem.getAttribute(attr) == '':
refElem.setAttributeNS(None, attr, elem.getAttribute(attr))
# now remove the xlink:href from refElem
refElem.removeAttributeNS(NS['XLINK'], 'href')
target_href = elem.getAttributeNS(NS['XLINK'], 'href')
if target_href:
# If the elem node had an xlink:href, then the
# refElem have to point to it as well to
# perserve the semantics of the image.
refElem.setAttributeNS(NS['XLINK'], 'href', target_href)
else:
# The elem node had no xlink:href reference,
# so we can simply remove the attribute.
refElem.removeAttributeNS(NS['XLINK'], 'href')
# now delete elem
elem.parentNode.removeChild(elem)