From 7ace4d36d44e9278c2ca14e0c401327af02f9b63 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Fri, 16 May 2025 09:24:18 +0200 Subject: letters to font: fix svg import (for simple files) (#3729) --- lib/extensions/letters_to_font.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/extensions/letters_to_font.py b/lib/extensions/letters_to_font.py index 8345af75..d9332a8a 100644 --- a/lib/extensions/letters_to_font.py +++ b/lib/extensions/letters_to_font.py @@ -14,7 +14,8 @@ from ..commands import ensure_symbol from ..i18n import _ from ..stitch_plan import generate_stitch_plan from ..svg import get_correction_transform -from ..svg.tags import INKSCAPE_GROUPMODE, INKSCAPE_LABEL, SVG_PATH_TAG +from ..svg.tags import (EMBROIDERABLE_TAGS, INKSCAPE_GROUPMODE, INKSCAPE_LABEL, + SVG_GROUP_TAG, SVG_PATH_TAG) from .base import InkstitchExtension @@ -79,15 +80,26 @@ class LettersToFont(InkstitchExtension): self.insert_baseline() def get_glyph_element(self, glyph): - stitch_plan = generate_stitch_plan(str(glyph), self.options.import_commands) - # we received a stitch plan wrapped in an svg document, we only need the stitch_plan group - # this group carries the name of the file, so we can search for it. label = os.path.basename(glyph) - search_string = f'.//*[@inkscape:label="{ escape(label) }"]' - stitch_plan = stitch_plan.xpath(search_string, namespaces=inkex.NSS)[0] - stitch_plan.attrib.pop(INKSCAPE_GROUPMODE) + if self.options.file_format.endswith('SVG'): + stitch_plan = self.get_svg_elements(glyph) + else: + stitch_plan = generate_stitch_plan(str(glyph), self.options.import_commands) + # we received a stitch plan wrapped in an svg document, we only need the stitch_plan group + # this group carries the name of the file, so we can search for it. + search_string = f'.//*[@inkscape:label="{ escape(label) }"]' + stitch_plan = stitch_plan.xpath(search_string, namespaces=inkex.NSS)[0] + stitch_plan.attrib.pop(INKSCAPE_GROUPMODE) stitch_plan.label = label return stitch_plan + def get_svg_elements(self, glyph): + glyph_svg = self.load(glyph).getroot() + glyph_group = inkex.Group() + # move all embroiderable child elements and groups of the svg file into a group + for child in glyph_svg.iterchildren((SVG_GROUP_TAG, EMBROIDERABLE_TAGS)): + glyph_group.add(child) + return glyph_group + def insert_baseline(self): self.svg.namedview.add_guide(position=0.0, name="baseline") -- cgit v1.2.3