diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2025-08-27 18:01:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-27 18:01:59 +0200 |
| commit | 714c1aa8eeb9ffb2853ce37a23c8b21ada7e8838 (patch) | |
| tree | 3da6c58e92975b1f1503890e82f3985dfe2576de /lib/elements | |
| parent | 2a49dadfa32c23d3d5b3359b064118bd18be1030 (diff) | |
color fixes (#3936)
Diffstat (limited to 'lib/elements')
| -rw-r--r-- | lib/elements/element.py | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py index 4aaf7580..d830012f 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -200,30 +200,29 @@ class EmbroideryElement(object): style = None return style - @property - @cache - def fill_color(self): + def _get_color(self, node, color_location, default=None): try: - color = self.node.get_computed_style("fill") + color = node.get_computed_style(color_location) + if isinstance(color, inkex.LinearGradient) and len(color.stops) == 1: + # Inkscape swatches set as a linear gradient with only one stop color + # Ink/Stitch should render the color correctly + color = self._get_color(color.stops[0], "stop-color", default) 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" + # TODO: This will also apply to currentcolor and alike which will not render + color = default return color @property @cache + def fill_color(self): + return self._get_color(self.node, "fill", "black") + + @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 + return self._get_color(self.node, "stroke") @property @cache |
