diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2025-07-19 22:30:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-19 22:30:15 +0200 |
| commit | ffc0db1ddf2f790fecaa67cdacec87f207e999e8 (patch) | |
| tree | 9938f5a242ca6bb1ac045dd7aed96b6097f6c629 /lib/svg | |
| parent | fdd3dbc956cd9d2be10bcbf4834e47dd89fcb754 (diff) | |
Convert to satin internally (3874)
Diffstat (limited to 'lib/svg')
| -rw-r--r-- | lib/svg/__init__.py | 10 | ||||
| -rw-r--r-- | lib/svg/path.py | 13 | ||||
| -rw-r--r-- | lib/svg/styles.py | 31 |
3 files changed, 50 insertions, 4 deletions
diff --git a/lib/svg/__init__.py b/lib/svg/__init__.py index b17a37f0..6694d534 100644 --- a/lib/svg/__init__.py +++ b/lib/svg/__init__.py @@ -4,8 +4,10 @@ # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. from .guides import get_guides -from .path import apply_transforms, get_node_transform, get_correction_transform, line_strings_to_csp, point_lists_to_csp, line_strings_to_path -from .path import apply_transforms, get_node_transform, get_correction_transform, line_strings_to_csp, point_lists_to_csp +from .path import (apply_transforms, get_correction_transform, + get_node_transform, line_strings_to_coordinate_lists, + line_strings_to_csp, line_strings_to_path, + point_lists_to_csp) from .rendering import color_block_to_point_lists, render_stitch_plan -from .svg import get_document, generate_unique_id -from .units import *
\ No newline at end of file +from .svg import generate_unique_id, get_document +from .units import * diff --git a/lib/svg/path.py b/lib/svg/path.py index 5e6e7007..a7c7b1ca 100644 --- a/lib/svg/path.py +++ b/lib/svg/path.py @@ -85,6 +85,19 @@ def get_correction_transform(node: inkex.BaseElement, child=False) -> str: return str(transform) +def line_strings_to_coordinate_lists(line_strings): + try: + # This lets us accept a MultiLineString or a list. + line_strings = line_strings.geoms + except AttributeError: + pass + + if line_strings is None: + return None + + return [list(ls.coords) for ls in line_strings] + + def line_strings_to_csp(line_strings): try: # This lets us accept a MultiLineString or a list. diff --git a/lib/svg/styles.py b/lib/svg/styles.py new file mode 100644 index 00000000..c3daaf19 --- /dev/null +++ b/lib/svg/styles.py @@ -0,0 +1,31 @@ +# Authors: see git history +# +# Copyright (c) 2025 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +from shapely.geometry import JOIN_STYLE + + +def get_join_style_args(element): + """Convert svg line join style to shapely offset_curve arguments.""" + + args = { + # mitre is the default per SVG spec + 'join_style': JOIN_STYLE.mitre + } + + element_join_style = element.get_style('stroke-linejoin') + + if element_join_style is not None: + if element_join_style == "miter": + args['join_style'] = JOIN_STYLE.mitre + + # 4 is the default per SVG spec + miter_limit = float(element.get_style('stroke-miterlimit', 4)) + args['mitre_limit'] = miter_limit + elif element_join_style == "bevel": + args['join_style'] = JOIN_STYLE.bevel + elif element_join_style == "round": + args['join_style'] = JOIN_STYLE.round + + return args |
