pull/3944/head
Kaalleen 2025-08-27 18:01:59 +02:00 zatwierdzone przez GitHub
rodzic 2a49dadfa3
commit 714c1aa8ee
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 32 dodań i 21 usunięć

Wyświetl plik

@ -200,31 +200,30 @@ class EmbroideryElement(object):
style = None style = None
return style return style
@property def _get_color(self, node, color_location, default=None):
@cache
def fill_color(self):
try: try:
color = self.node.get_computed_style("fill") color = node.get_computed_style(color_location)
except (inkex.ColorError, ValueError): if isinstance(color, inkex.LinearGradient) and len(color.stops) == 1:
# SVG spec says the default fill is black # Inkscape swatches set as a linear gradient with only one stop color
# A color error could show up, when an element has an unrecognized color name # Ink/Stitch should render the color correctly
# A value error could show up, when for example when an element links to a non-existent gradient color = self._get_color(color.stops[0], "stop-color", default)
# 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): except (inkex.ColorError, ValueError):
# A color error could show up, when an element has an unrecognized color name # 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 # 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 # TODO: This will also apply to currentcolor and alike which will not render
return None color = default
return color return color
@property
@cache
def fill_color(self):
return self._get_color(self.node, "fill", "black")
@property
@cache
def stroke_color(self):
return self._get_color(self.node, "stroke")
@property @property
@cache @cache
def stroke_scale(self): def stroke_scale(self):

Wyświetl plik

@ -113,8 +113,11 @@ def gradient_shapes_and_attributes(element, shape, unit_multiplier):
# e.g. url(#linearGradient872) -> linearGradient872 # e.g. url(#linearGradient872) -> linearGradient872
gradient = element.gradient gradient = element.gradient
gradient.apply_transform() gradient.apply_transform()
point1 = (float(gradient.get('x1')), float(gradient.get('y1'))) # Note: when x and y are given in percentage within the svg file (which can happen in inkscape-non-native-files),
point2 = (float(gradient.get('x2')), float(gradient.get('y2'))) # gradient returns (0, 0) for both positions and will not render correctly.
# When the object is moved just once in inkscape, values are updated and this will work again.
point1 = (gradient.x1(), gradient.y1())
point2 = (gradient.x2(), gradient.y2())
# get 90° angle to calculate the splitting angle # get 90° angle to calculate the splitting angle
transform = -Transform(get_correction_transform(element.node, child=True)) transform = -Transform(get_correction_transform(element.node, child=True))
line = DirectedLineSegment(transform.apply_to_point(point1), transform.apply_to_point(point2)) line = DirectedLineSegment(transform.apply_to_point(point1), transform.apply_to_point(point2))
@ -146,7 +149,7 @@ def gradient_shapes_and_attributes(element, shape, unit_multiplier):
split_line = rotate(split_line, angle, origin=split_point, use_radians=True) split_line = rotate(split_line, angle, origin=split_point, use_radians=True)
offset_line = split_line.parallel_offset(1, 'right') offset_line = split_line.parallel_offset(1, 'right')
polygon = split(shape, split_line) polygon = split(shape, split_line)
color = verify_color(stop_styles[i]['stop-color']) color = _get_and_verify_color(stop_styles, gradient, i)
# does this gradient line split the shape # does this gradient line split the shape
offset_outside_shape = len(polygon.geoms) == 1 offset_outside_shape = len(polygon.geoms) == 1
for poly in polygon.geoms: for poly in polygon.geoms:
@ -178,6 +181,15 @@ def gradient_shapes_and_attributes(element, shape, unit_multiplier):
return polygons, attributes return polygons, attributes
def _get_and_verify_color(stop_styles, gradient, iterator):
try:
color = verify_color(stop_styles[iterator]['stop-color'])
except KeyError:
color = gradient.stops[iterator].get_computed_style('stop-color')
stop_styles[iterator]['stop-color'] = color
return color
def verify_color(color): def verify_color(color):
try: try:
Color(color) Color(color)