diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2023-09-07 19:30:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-07 19:30:09 +0200 |
| commit | 998edba99ecf4bf2961a11a2feba791a4addb026 (patch) | |
| tree | b87846a9ec393f63556091a3461fbc833f4d33a1 /lib/extensions/gradient_blocks.py | |
| parent | 98273652fd4442cb85b32b3c7b665580288d8cb4 (diff) | |
gradient_blocks: unit fix (#2505)
Diffstat (limited to 'lib/extensions/gradient_blocks.py')
| -rw-r--r-- | lib/extensions/gradient_blocks.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/extensions/gradient_blocks.py b/lib/extensions/gradient_blocks.py index b8142d7f..f94582f0 100644 --- a/lib/extensions/gradient_blocks.py +++ b/lib/extensions/gradient_blocks.py @@ -52,7 +52,7 @@ class GradientBlocks(CommandsExtension): correction_transform = get_correction_transform(element.node) style = element.node.style index = parent.index(element.node) - fill_shapes, attributes = gradient_shapes_and_attributes(element, element.shape) + fill_shapes, attributes = gradient_shapes_and_attributes(element, element.shape, self.svg.viewport_to_unit(1)) # reverse order so we can always insert with the same index number fill_shapes.reverse() attributes.reverse() @@ -127,7 +127,7 @@ class GradientBlocks(CommandsExtension): return path -def gradient_shapes_and_attributes(element, shape): +def gradient_shapes_and_attributes(element, shape, unit_multiplier): # e.g. url(#linearGradient872) -> linearGradient872 color = element.color[5:-1] xpath = f'.//svg:defs/svg:linearGradient[@id="{color}"]' @@ -144,6 +144,7 @@ def gradient_shapes_and_attributes(element, shape): # create bbox polygon to calculate the length necessary to make sure that # the gradient splitter lines will cut the entire design + # bounding_box returns the value in viewport units, we need to convert the length later to px bbox = element.node.bounding_box() bbox_polygon = shgeo.Polygon([(bbox.left, bbox.top), (bbox.right, bbox.top), (bbox.right, bbox.bottom), (bbox.left, bbox.bottom)]) @@ -159,7 +160,7 @@ def gradient_shapes_and_attributes(element, shape): for i, offset in enumerate(offsets): shape_rest = [] split_point = shgeo.Point(line.point_at_ratio(float(offset))) - length = split_point.hausdorff_distance(bbox_polygon) + length = split_point.hausdorff_distance(bbox_polygon) / unit_multiplier 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) |
