From 6f282829537b69b8628b901cc717f18222ff33a0 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Mon, 27 Oct 2025 18:09:21 +0100 Subject: Lettering: add spacing options (#4020) --- lib/extensions/batch_lettering.py | 17 +++++++++++++---- lib/extensions/lettering_along_path.py | 25 ++++++++++++++++++------- 2 files changed, 31 insertions(+), 11 deletions(-) (limited to 'lib/extensions') diff --git a/lib/extensions/batch_lettering.py b/lib/extensions/batch_lettering.py index c0581e76..045a1223 100644 --- a/lib/extensions/batch_lettering.py +++ b/lib/extensions/batch_lettering.py @@ -42,6 +42,9 @@ class BatchLettering(InkstitchExtension): self.arg_parser.add_argument('--trim', type=str, default='off', dest='trim') self.arg_parser.add_argument('--use-command-symbols', type=Boolean, default=False, dest='command_symbols') self.arg_parser.add_argument('--text-align', type=str, default='left', dest='text_align') + self.arg_parser.add_argument('--letter_spacing', type=float, default=0, dest='letter_spacing') + self.arg_parser.add_argument('--word_spacing', type=float, default=0, dest='word_spacing') + self.arg_parser.add_argument('--line_height', type=float, default=0, dest='line_height') self.arg_parser.add_argument('--text-position', type=str, default='left', dest='text_position') @@ -60,7 +63,7 @@ class BatchLettering(InkstitchExtension): if not self.options.font: errormsg(_("Please specify a font")) return - self.font = get_font_by_name(self.options.font) + self.font = get_font_by_name(self.options.font, False) if self.font is None: errormsg(_("Please specify a valid font name.")) errormsg(_("You can find a list with all font names on our website: https://inkstitch.org/fonts/font-library/")) @@ -194,10 +197,13 @@ class BatchLettering(InkstitchExtension): "text_align": self.text_align, "back_and_forth": True, "font": self.font.marked_custom_font_id, - "scale": self.scale * 100, + "scale": int(self.scale * 100), "trim_option": self.trim, "use_trim_symbols": self.options.command_symbols, - "color_sort": self.color_sort + "color_sort": self.color_sort, + "letter_spacing": self.options.letter_spacing, + "word_spacing": self.options.word_spacing, + "line_height": self.options.line_height }) lettering_group = Group() @@ -216,7 +222,10 @@ class BatchLettering(InkstitchExtension): trim_option=self.trim, use_trim_symbols=self.options.command_symbols, color_sort=self.color_sort, - text_align=self.text_align + text_align=self.text_align, + letter_spacing=self.options.letter_spacing, + word_spacing=self.options.word_spacing, + line_height=self.options.line_height ) destination_group.attrib['transform'] = f'scale({self.scale})' diff --git a/lib/extensions/lettering_along_path.py b/lib/extensions/lettering_along_path.py index 6f1ca7a6..4afc4416 100644 --- a/lib/extensions/lettering_along_path.py +++ b/lib/extensions/lettering_along_path.py @@ -72,11 +72,7 @@ class TextAlongPath: self.text = text self.path = Stroke(path).as_multi_line_string().geoms[0] self.text_position = text_position - - self.glyphs = [glyph for glyph in self.text.iterdescendants(SVG_GROUP_TAG) if glyph.get('inkstitch:letter-group', '') == 'glyph'] - if not self.glyphs: - errormsg(_("The text doesn't contain any glyphs.")) - return + self.glyphs = [] self.load_settings() self.font = get_font_by_id(self.settings.font, False) @@ -87,6 +83,10 @@ class TextAlongPath: self.font_scale = self.settings.scale / 100 self._reset_glyph_transforms() + if not self.glyphs: + errormsg(_("The text doesn't contain any glyphs.")) + return + hidden_commands = self.hide_commands() self.glyphs_along_path() self.restore_commands(hidden_commands) @@ -109,8 +109,14 @@ class TextAlongPath: None, # we don't know the font variant (?) self.settings.back_and_forth, self.settings.trim_option, - self.settings.use_trim_symbols + self.settings.use_trim_symbols, + 0, # color sort breaks the glyph structure needed for this method + self.settings.text_align, + self.settings.letter_spacing, + self.settings.word_spacing, + self.settings.line_height ) + self.glyphs = [glyph for glyph in rendered_text.iterdescendants(SVG_GROUP_TAG) if glyph.get('inkstitch:letter-group', '') == 'glyph'] self.bake_transforms_recursively(text_group) @@ -230,7 +236,12 @@ class TextAlongPath: "font": None, "scale": 100, "trim_option": 0, - "use_trim_symbols": False + "use_trim_symbols": False, + "color_sort": 0, + "text_align": 0, + "letter_spacing": 0, + "word_spacing": 0, + "line_height": 0 }) if INKSTITCH_LETTERING in self.text.attrib: -- cgit v1.2.3