From 497fbcfab5734aac889f15b72384a6a8631fffa4 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Mon, 3 Feb 2025 22:37:36 +0100 Subject: Add debug variable to enable sew stack elements (#3476) --- lib/lettering/font_variant.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lib/lettering/font_variant.py') 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) -- cgit v1.2.3