kopia lustrzana https://github.com/inkstitch/inkstitch
Fix some transforms ... (#2314)
* fix fill to stroke transform * remove empty leftover groups * gradient blocks transforms * gradient: do not ignore holespull/2316/head
rodzic
ef6f6580df
commit
8b20e518b5
|
@ -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
|
||||
|
|
|
@ -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']
|
||||
|
|
Ładowanie…
Reference in New Issue