summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2023-05-23 22:54:46 +0200
committerGitHub <noreply@github.com>2023-05-23 22:54:46 +0200
commit8b20e518b5e993b1ad4d657530171467a403af95 (patch)
tree6cc0bd9219f6b0e4cffe0528dbb2bc8ec448fb77
parentef6f6580df6e8fbce913eecc1fe7e0f8caf1315b (diff)
Fix some transforms ... (#2314)
* fix fill to stroke transform * remove empty leftover groups * gradient blocks transforms * gradient: do not ignore holes
-rw-r--r--lib/extensions/fill_to_stroke.py10
-rw-r--r--lib/extensions/gradient_blocks.py18
2 files changed, 20 insertions, 8 deletions
diff --git a/lib/extensions/fill_to_stroke.py b/lib/extensions/fill_to_stroke.py
index eca17c95..5672fb69 100644
--- a/lib/extensions/fill_to_stroke.py
+++ b/lib/extensions/fill_to_stroke.py
@@ -53,8 +53,8 @@ class FillToStroke(InkstitchExtension):
parent.insert(index, centerline_group)
for element in fill_shapes:
- transform = element.node.transform @ Transform(get_correction_transform(element.node, child=True))
- stroke_width = convert_unit(self.options.line_width_mm, self.svg.unit, 'mm')
+ transform = Transform(get_correction_transform(parent, child=True))
+ stroke_width = convert_unit(self.options.line_width_mm, 'px', 'mm')
color = element.node.style('fill')
style = f"fill:none;stroke:{ color };stroke-width:{ stroke_width }"
@@ -93,13 +93,19 @@ class FillToStroke(InkstitchExtension):
return fill_shapes, cut_lines
def _remove_elements(self):
+ parents = []
for element in self.elements:
# it is possible, that we get one element twice (if it has both, a fill and a stroke)
# just ignore the second time
try:
+ parents.append(element.node.getparent())
element.node.getparent().remove(element.node)
except AttributeError:
pass
+ # remove empty groups
+ for parent in set(parents):
+ if not parent.getchildren():
+ parent.getparent().remove(parent)
def _get_high_res_polygon(self, polygon):
# use running stitch method
diff --git a/lib/extensions/gradient_blocks.py b/lib/extensions/gradient_blocks.py
index 5d8318b6..b8142d7f 100644
--- a/lib/extensions/gradient_blocks.py
+++ b/lib/extensions/gradient_blocks.py
@@ -7,7 +7,7 @@ from math import degrees, pi
from inkex import DirectedLineSegment, PathElement, Transform, errormsg
from shapely import geometry as shgeo
-from shapely.affinity import affine_transform, rotate
+from shapely.affinity import rotate
from shapely.geometry import Point
from shapely.ops import nearest_points, split
@@ -71,7 +71,7 @@ class GradientBlocks(CommandsExtension):
is_gradient = attributes[i]['is_gradient']
angle = degrees(attributes[i]['angle'])
angle = f'{angle: .2f}'
- d = "M " + " ".join([f'{x}, {y}' for x, y in list(shape.exterior.coords)]) + " Z"
+ d = self._element_to_path(shape)
block = PathElement(attrib={
"id": self.uniqueId("path"),
"style": str(style),
@@ -119,6 +119,13 @@ class GradientBlocks(CommandsExtension):
pos = line.point_at_length(line.length + 20)
return Point(pos)
+ def _element_to_path(self, shape):
+ coords = list(shape.exterior.coords)
+ for interior in shape.interiors:
+ coords.extend(interior.coords)
+ path = "M " + " ".join([f'{x}, {y}' for x, y in coords]) + " Z"
+ return path
+
def gradient_shapes_and_attributes(element, shape):
# e.g. url(#linearGradient872) -> linearGradient872
@@ -129,10 +136,12 @@ def gradient_shapes_and_attributes(element, shape):
point1 = (float(gradient.get('x1')), float(gradient.get('y1')))
point2 = (float(gradient.get('x2')), float(gradient.get('y2')))
# get 90° angle to calculate the splitting angle
- line = DirectedLineSegment(point1, point2)
+ transform = -Transform(get_correction_transform(element.node, child=True))
+ line = DirectedLineSegment(transform.apply_to_point(point1), transform.apply_to_point(point2))
angle = line.angle - (pi / 2)
# Ink/Stitch somehow turns the stitch angle
stitch_angle = angle * -1
+
# create bbox polygon to calculate the length necessary to make sure that
# the gradient splitter lines will cut the entire design
bbox = element.node.bounding_box()
@@ -154,9 +163,6 @@ def gradient_shapes_and_attributes(element, shape):
split_line = shgeo.LineString([(split_point.x - length - 2, split_point.y),
(split_point.x + length + 2, split_point.y)])
split_line = rotate(split_line, angle, origin=split_point, use_radians=True)
- transform = -Transform(get_correction_transform(element.node))
- transform = list(transform.to_hexad())
- split_line = affine_transform(split_line, transform)
offset_line = split_line.parallel_offset(1, 'right')
polygon = split(shape, split_line)
color = stop_styles[i]['stop-color']