diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2025-02-03 22:37:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-03 22:37:36 +0100 |
| commit | 497fbcfab5734aac889f15b72384a6a8631fffa4 (patch) | |
| tree | 1f1a690a6108d7e4e0fac599d4e554edae9db6f9 /lib/lettering | |
| parent | e1c6d8c5956c7c3c5e158c1f7415edd5bc1a0cc1 (diff) | |
Add debug variable to enable sew stack elements (#3476)
Diffstat (limited to 'lib/lettering')
| -rw-r--r-- | lib/lettering/font.py | 18 | ||||
| -rw-r--r-- | lib/lettering/font_variant.py | 19 |
2 files changed, 33 insertions, 4 deletions
diff --git a/lib/lettering/font.py b/lib/lettering/font.py index 1ae08896..1805b0b4 100644 --- a/lib/lettering/font.py +++ b/lib/lettering/font.py @@ -5,6 +5,7 @@ import json import os +from collections import defaultdict from copy import deepcopy from random import randint @@ -17,12 +18,12 @@ from ..extensions.lettering_custom_font_dir import get_custom_font_dir from ..i18n import _, get_languages from ..marker import MARKER, ensure_marker, has_marker, is_grouped_with_marker from ..stitches.auto_satin import auto_satin +from ..svg.clip import get_clips from ..svg.tags import (CONNECTION_END, CONNECTION_START, EMBROIDERABLE_TAGS, INKSCAPE_LABEL, INKSTITCH_ATTRIBS, SVG_GROUP_TAG, SVG_PATH_TAG, SVG_USE_TAG, XLINK_HREF) from ..utils import Point from .font_variant import FontVariant -from collections import defaultdict class FontError(InkstitchException): @@ -599,6 +600,21 @@ class Font(object): or element.get_id().startswith('command_connector')): continue + clips = get_clips(element) + if len(clips) > 1: + # multiple clips: wrap the element into clipped groups + parent = element.getparent() + index = parent.index(element) + for clip in clips: + new_group = inkex.Group() + new_group.clip = clip + parent.insert(index, new_group) + new_group.append(element) + element = new_group + elif len(clips) == 1: + # only one clip: we can apply the clip directly to the element + element.clip = clips[0] + # get glyph group to calculate transform glyph_group = None for ancestor in element.ancestors(group): diff --git a/lib/lettering/font_variant.py b/lib/lettering/font_variant.py index 9d3793a6..baf7c09f 100644 --- a/lib/lettering/font_variant.py +++ b/lib/lettering/font_variant.py @@ -4,6 +4,7 @@ # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. import os +from collections import defaultdict import inkex @@ -99,15 +100,20 @@ class FontVariant(object): group.attrib.pop('display', None) def _apply_transforms(self, svg): + self.clip_transforms = defaultdict(list) # apply transforms to paths and use tags - for element in svg.iterdescendants((SVG_PATH_TAG, SVG_USE_TAG)): + for element in svg.iterdescendants((SVG_PATH_TAG, SVG_USE_TAG, SVG_GROUP_TAG)): transform = element.composed_transform() + + if element.clip is not None: + self.clip_transforms[element.clip] = element.composed_transform() + if element.tag == SVG_GROUP_TAG: + continue if element.tag == SVG_PATH_TAG: path = element.path.transform(transform) element.set_path(path) element.attrib.pop("transform", None) - - if element.tag == SVG_USE_TAG: + elif element.tag == SVG_USE_TAG: oldx = element.get('x', 0) oldy = element.get('y', 0) newx, newy = transform.apply_to_point((oldx, oldy)) @@ -115,6 +121,13 @@ class FontVariant(object): element.set('y', newy) element.attrib.pop("transform", None) + for clip, transform in self.clip_transforms.items(): + for element in clip.iterdescendants(): + if element.tag == SVG_PATH_TAG: + path = element.path.transform(transform) + element.set_path(path) + element.attrib.pop("transform", None) + # remove transforms after they have been applied for group in svg.iterdescendants(SVG_GROUP_TAG): group.attrib.pop('transform', None) |
