From 2235ec6571601e12be7eb3c74907668fb68bebd4 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Fri, 11 Jul 2025 22:14:52 +0200 Subject: Fix issue with bad color names (#3816) * fix issue with bad color names and define element colors at one place and reuse * fix bad tartan color * verify color in gradient block * add thread color tests * use default color behavior for elements linked to non-existing definitions (gradients) * Added mypy change for tests (authored by: CapellanCitizen) --- lib/elements/element.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'lib/elements/element.py') diff --git a/lib/elements/element.py b/lib/elements/element.py index 7b558506..1ca78b04 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -198,10 +198,33 @@ class EmbroideryElement(object): style = element_style.get(style_name, default) if style in ['none', 'None']: style = None - elif style == 'currentColor': - style = element_style(style_name) return style + @property + @cache + def fill_color(self): + try: + color = self.node.get_computed_style("fill") + except (inkex.ColorError, ValueError): + # SVG spec says the default fill is black + # A color error could show up, when an element has an unrecognized color name + # A value error could show up, when for example when an element links to a non-existent gradient + # TODO: This will also apply to currentcolor and alike which will render in black + return "black" + return color + + @property + @cache + def stroke_color(self): + try: + color = self.node.get_computed_style("stroke") + except (inkex.ColorError, ValueError): + # A color error could show up, when an element has an unrecognized color name + # A value error could show up, when for example when an element links to a non-existent gradient + # TODO: This will also apply to currentcolor and alike which will not render + return None + return color + @property @cache def stroke_scale(self): -- cgit v1.2.3