diff options
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 |
