From 714c1aa8eeb9ffb2853ce37a23c8b21ada7e8838 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Wed, 27 Aug 2025 18:01:59 +0200 Subject: color fixes (#3936) --- lib/elements/element.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'lib/elements/element.py') 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 -- cgit v1.2.3