another small fix in replace color and alpha

This commit is contained in:
Mario Voigt 2023-01-20 12:44:30 +01:00
parent 380fc41cf6
commit d292a69d5f

View File

@ -52,8 +52,17 @@ class ReplaceColorAndAlpha(inkex.EffectExtension):
except Exception as e: except Exception as e:
inkex.utils.debug(e) inkex.utils.debug(e)
pass pass
svg = self.document.getroot()
for element in svg.iter("*"): elements = []
if self.svg.selected:
for id, node in self.svg.selected.items():
elements.append(node)
else:
svg = self.document.getroot()
for svg_element in svg.iter("*"):
elements.append(svg_element)
for element in elements:
style = element.get('style') style = element.get('style')
if style: if style:
if (style.lower().find('fill:#'+fr[:6]) != -1 and len(fr) == 6) or (style.lower().find('fill-opacity:'+alphaFr[:4]) != -1 and len(fr)==8 and style.lower().find('fill:#'+fr[:6]) != -1): if (style.lower().find('fill:#'+fr[:6]) != -1 and len(fr) == 6) or (style.lower().find('fill-opacity:'+alphaFr[:4]) != -1 and len(fr)==8 and style.lower().find('fill:#'+fr[:6]) != -1):
@ -69,13 +78,13 @@ class ReplaceColorAndAlpha(inkex.EffectExtension):
if (style.lower().find('stroke:#'+fr[:6]) != -1 and len(fr) == 6) or (style.lower().find('stroke:#'+fr[:6]) != -1 and style.lower().find('stroke-opacity:'+alphaFr[:4]) != -1 and len(fr)==8): if (style.lower().find('stroke:#'+fr[:6]) != -1 and len(fr) == 6) or (style.lower().find('stroke:#'+fr[:6]) != -1 and style.lower().find('stroke-opacity:'+alphaFr[:4]) != -1 and len(fr)==8):
style = re.sub('stroke-opacity:.*?(;|$)', style = re.sub('stroke-opacity:.*?(;|$)',
'\\1', '\\1',
style) style)
style = re.sub(r'stroke:#.*?(;|$)', style = re.sub(r'stroke:#.*?(;|$)',
'stroke:#' + to[:6] + '\\1', 'stroke:#' + to[:6] + '\\1',
style) style)
style = style + ";stroke-opacity:" + alphaTo style = style + ";stroke-opacity:" + alphaTo
element.set('style',style) element.set('style',style)
sys.stdout = saveout sys.stdout = saveout
if __name__ == '__main__': if __name__ == '__main__':
ReplaceColorAndAlpha().run() ReplaceColorAndAlpha().run()