diff options
Diffstat (limited to 'lib/elements')
| -rw-r--r-- | lib/elements/element.py | 27 | ||||
| -rw-r--r-- | lib/elements/fill_stitch.py | 15 | ||||
| -rw-r--r-- | lib/elements/satin_column.py | 2 | ||||
| -rw-r--r-- | lib/elements/stroke.py | 2 | ||||
| -rw-r--r-- | lib/elements/utils.py | 4 |
5 files changed, 37 insertions, 13 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? # diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 555c7e09..7ce3188a 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -7,7 +7,7 @@ import math import re import numpy as np -from inkex import LinearGradient +from inkex import Color, ColorError, LinearGradient from shapely import geometry as shgeo from shapely import set_precision from shapely.errors import GEOSException @@ -632,14 +632,12 @@ class FillStitch(EmbroideryElement): @property def color(self): - # SVG spec says the default fill is black - return self.get_style("fill", "#000000") + return self.fill_color @property def gradient(self): - gradient = self.node.get_computed_style("fill") - if isinstance(gradient, LinearGradient): - return gradient + if isinstance(self.fill_color, LinearGradient): + return self.fill_color return None @property @@ -1032,7 +1030,10 @@ class FillStitch(EmbroideryElement): def do_underlay(self, shape, starting_point): color = self.color if self.gradient is not None and self.fill_method == 'linear_gradient_fill': - color = self.gradient.stops[0].get_computed_style('stop-color') + try: + color = self.gradient.stops[0].get_computed_style('stop-color') + except ColorError: + color = Color('black') stitch_groups = [] for i in range(len(self.fill_underlay_angle)): diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index ff5cfe86..3a29aca7 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -243,7 +243,7 @@ class SatinColumn(EmbroideryElement): @property def color(self): - return self.get_style("stroke") + return self.stroke_color @property @param('zigzag_spacing_mm', diff --git a/lib/elements/stroke.py b/lib/elements/stroke.py index 6e01151d..3740371f 100644 --- a/lib/elements/stroke.py +++ b/lib/elements/stroke.py @@ -50,7 +50,7 @@ class Stroke(EmbroideryElement): @property def color(self): - color = self.get_style("stroke") + color = self.stroke_color if self.cutwork_needle is not None: color = ThreadColor(color, description=self.cutwork_needle, chart=self.cutwork_needle) return color diff --git a/lib/elements/utils.py b/lib/elements/utils.py index 6aec1cc2..43c2387d 100644 --- a/lib/elements/utils.py +++ b/lib/elements/utils.py @@ -47,9 +47,9 @@ def node_to_elements(node, clone_to_element=False) -> List[EmbroideryElement]: if not sew_stack.sew_stack_only: element = EmbroideryElement(node) - if element.get_style("fill", "black") and not element.get_style('fill-opacity', 1) == "0": + if element.fill_color is not None and not element.get_style('fill-opacity', 1) == "0": elements.append(FillStitch(node)) - if element.get_style("stroke"): + if element.stroke_color is not None: if element.get_boolean_param("satin_column") and len(element.path) > 1: elements.append(SatinColumn(node)) elif not is_command(element.node): |
