diff options
Diffstat (limited to 'lib/extensions/gradient_blocks.py')
| -rw-r--r-- | lib/extensions/gradient_blocks.py | 18 |
1 files changed, 12 insertions, 6 deletions
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'] |
