diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2024-06-21 16:47:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-21 16:47:12 +0200 |
| commit | 4e143db33a547571c90ad2736e9c0bbd53759801 (patch) | |
| tree | 647392882556301055bd834ccc81901ede4c9b4d /lib/stitches | |
| parent | aa41f8b1abd87e5daa6878dae87d10b02f981edc (diff) | |
Ignore empty color blocks in linear gradient fill (#3003)
Diffstat (limited to 'lib/stitches')
| -rw-r--r-- | lib/stitches/linear_gradient_fill.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/stitches/linear_gradient_fill.py b/lib/stitches/linear_gradient_fill.py index ea248d98..c0c07e0d 100644 --- a/lib/stitches/linear_gradient_fill.py +++ b/lib/stitches/linear_gradient_fill.py @@ -47,9 +47,9 @@ def _get_lines_and_colors(shape, fill): gradient_start_line_index = round(bottom_line.project(gradient_start) / fill.row_spacing) if gradient_start_line_index == 0: gradient_start_line_index = -round(LineString([gradient_start, gradient_end]).project(Point(bottom_line.coords[0])) / fill.row_spacing) - stop_color_line_indices = [gradient_start_line_index] + stop_color_line_indices = [] gradient_line = LineString([gradient_start, gradient_end]) - for offset in offsets[1:]: + for offset in offsets: stop_color_line_indices.append(round((gradient_line.length * offset) / fill.row_spacing) + gradient_start_line_index) return lines, colors, stop_color_line_indices @@ -70,13 +70,12 @@ def _get_gradient_info(fill, bbox): # it would be easier if we just used fill.gradient.stop_styles to collect them # but inkex/tinycss fails on stop color styles when it is not in the style attribute, but in it's own stop-color attribute colors = [] - for stop in fill.gradient.stops: + for i, stop in enumerate(fill.gradient.stops): color = stop.get_computed_style('stop-color') opacity = stop.get_computed_style('stop-opacity') - if float(opacity) > 0: - colors.append(color) - else: - colors.append('none') + if float(opacity) == 0: + color = 'none' + colors.append(color) gradient_start, gradient_end = gradient_start_end(fill.node, fill.gradient) angle = gradient_angle(fill.node, fill.gradient) return angle, colors, offsets, Point(list(gradient_start)), Point(list(gradient_end)) @@ -170,7 +169,7 @@ def _get_color_lines(lines, colors, stop_color_line_indices): prev += 1 line_index += 1 total_lines = line_index - prev - sections = floor(sqrt(total_lines)) + sections = floor(sqrt(max(total_lines, 0))) color1 = [] color2 = [] @@ -205,6 +204,9 @@ def _get_color_lines(lines, colors, stop_color_line_indices): max_count ) + if not color1 or not color2: + continue + # mirror the first half of the color section to receive the full section second_half = color2[-1] * 2 + 1 |
