diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2025-07-11 22:14:52 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-11 22:14:52 +0200 |
| commit | 2235ec6571601e12be7eb3c74907668fb68bebd4 (patch) | |
| tree | 61d85cb615a1b2327283e89f09592e1eb85ad91c /lib/elements/element.py | |
| parent | 7bd72274780ccaeae8bbae6e761341079df21ecb (diff) | |
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)
Diffstat (limited to 'lib/elements/element.py')
| -rw-r--r-- | lib/elements/element.py | 27 |
1 files changed, 25 insertions, 2 deletions
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,12 +198,35 @@ 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): # How wide is the stroke, after the transforms are applied? # |
