diff options
| -rw-r--r-- | lib/extensions/lettering_along_path.py | 31 | ||||
| -rw-r--r-- | lib/lettering/__init__.py | 1 | ||||
| -rw-r--r-- | lib/lettering/utils.py | 29 |
3 files changed, 54 insertions, 7 deletions
diff --git a/lib/extensions/lettering_along_path.py b/lib/extensions/lettering_along_path.py index c7b950b1..bf817c55 100644 --- a/lib/extensions/lettering_along_path.py +++ b/lib/extensions/lettering_along_path.py @@ -11,6 +11,7 @@ from inkex.units import convert_unit from ..elements import Stroke from ..i18n import _ +from ..lettering import get_font_by_id from ..svg import get_correction_transform from ..svg.tags import EMBROIDERABLE_TAGS, INKSTITCH_LETTERING, SVG_GROUP_TAG from ..utils import DotDict @@ -40,12 +41,37 @@ class LetteringAlongPath(InkstitchExtension): return self.load_settings(text) + + if glyphs[0].get('transform', None) is not None: + glyphs = self._reset_glyph_transforms(text, glyphs) + path = Stroke(path).as_multi_line_string().geoms[0] hidden_commands = self.hide_commands(glyphs) space_indices, stretch_space, text_baseline = self.get_position_and_stretch_values(path, text, glyphs) self.transform_glyphs(glyphs, path, stretch_space, space_indices, text_baseline) self.restore_commands(hidden_commands) + def _reset_glyph_transforms(self, text_group, glyphs): + font = get_font_by_id(self.settings.font) + if font is not None: + if self.settings.scale != 100: + try: + text_group = list(text_group.iterchildren(SVG_GROUP_TAG))[0] + except IndexError: + pass + for glyph in text_group.iterchildren(): + text_group.remove(glyph) + text = font.render_text( + self.settings.text, + text_group, + None, # we don't know the font variant (?) + self.settings.back_and_forth, + self.settings.trim_option, + self.settings.use_trim_symbols + ) + return [glyph for glyph in text.iterdescendants(SVG_GROUP_TAG) if glyph.label and len(glyph.label) == 1] + return glyphs + def get_position_and_stretch_values(self, path, text, glyphs): text_bbox = glyphs[0].getparent().bounding_box() text_baseline = text_bbox.bottom @@ -82,7 +108,7 @@ class LetteringAlongPath(InkstitchExtension): command.style['display'] = "inline" def transform_glyphs(self, glyphs, path, stretch_space, space_indices, text_baseline): - text_scale = Transform(f'scale({self.settings["scale"] / 100})') + text_scale = Transform(f'scale({self.settings.scale / 100})') distance = 0 old_bbox = None i = 0 @@ -129,7 +155,8 @@ class LetteringAlongPath(InkstitchExtension): "back_and_forth": False, "font": None, "scale": 100, - "trim_option": 0 + "trim_option": 0, + "use_trim_symbols": False }) if INKSTITCH_LETTERING in text.attrib: diff --git a/lib/lettering/__init__.py b/lib/lettering/__init__.py index dcfccaba..60d47581 100644 --- a/lib/lettering/__init__.py +++ b/lib/lettering/__init__.py @@ -5,3 +5,4 @@ from .font import Font, FontError from .utils import get_font_list +from .utils import get_font_by_id diff --git a/lib/lettering/utils.py b/lib/lettering/utils.py index f4e2b0a7..d1ec1b8e 100644 --- a/lib/lettering/utils.py +++ b/lib/lettering/utils.py @@ -13,23 +13,42 @@ from ..utils import get_bundled_dir def get_font_list(): + font_paths = get_font_paths() + fonts = [] + for font_path in font_paths: + try: + font_dirs = os.listdir(font_path) + except OSError: + continue + + for font_dir in font_dirs: + font = Font(os.path.join(font_path, font_dir)) + if font.marked_custom_font_name == "" or font.marked_custom_font_id == "": + continue + fonts.append(font) + return fonts + + +def get_font_paths(): font_paths = { get_bundled_dir("fonts"), os.path.expanduser("~/.inkstitch/fonts"), os.path.join(appdirs.user_config_dir('inkstitch'), 'fonts'), get_custom_font_dir() } + return font_paths + +def get_font_by_id(font_id): + font_paths = get_font_paths() for font_path in font_paths: try: font_dirs = os.listdir(font_path) except OSError: continue - for font_dir in font_dirs: font = Font(os.path.join(font_path, font_dir)) - if font.marked_custom_font_name == "" or font.marked_custom_font_id == "": - continue - fonts.append(font) - return fonts + if font.id == font_id: + return font + return None |
