summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/extensions/lettering_along_path.py45
-rw-r--r--lib/lettering/utils.py4
-rw-r--r--templates/lettering_along_path.xml10
3 files changed, 38 insertions, 21 deletions
diff --git a/lib/extensions/lettering_along_path.py b/lib/extensions/lettering_along_path.py
index d059bb14..6f1ca7a6 100644
--- a/lib/extensions/lettering_along_path.py
+++ b/lib/extensions/lettering_along_path.py
@@ -79,24 +79,26 @@ class TextAlongPath:
return
self.load_settings()
- self.font = get_font_by_id(self.settings.font)
+ self.font = get_font_by_id(self.settings.font, False)
if self.font is None:
errormsg(_("Couldn't identify the font specified in the lettering group."))
return
self.font_scale = self.settings.scale / 100
-
- if self.glyphs[0].get('transform', None) is not None:
- self._reset_glyph_transforms()
+ self._reset_glyph_transforms()
hidden_commands = self.hide_commands()
self.glyphs_along_path()
self.restore_commands(hidden_commands)
def _reset_glyph_transforms(self):
+ # reset text transforms
+ self.text.set('transform', get_correction_transform(self.text))
+
if self.font is not None:
try:
text_group = list(self.text.iterchildren(SVG_GROUP_TAG))[0]
+ text_group.set('transform', f'scale({self.font_scale})')
except IndexError:
pass
for glyph in text_group.iterchildren():
@@ -110,19 +112,29 @@ class TextAlongPath:
self.settings.use_trim_symbols
)
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)
+
+ def bake_transforms_recursively(self, element):
+ '''applies transforms of the text group to the glyph group'''
+ for child in element:
+ child.transform = element.transform @ child.transform
+ if child.tag == SVG_GROUP_TAG and not child.get('inkstitch:letter-group', '') == 'glyph':
+ self.bake_transforms_recursively(child)
+ element.transform = None
def glyphs_along_path(self):
path = self.path
- for text_line in self.text.getchildren()[0].iterchildren():
- self.transform_glyphs(path, text_line)
+ for i, text_line in enumerate(self.text.getchildren()[0].iterchildren()):
+ self.transform_glyphs(path, text_line, i)
# offset path for the next line
- path = path.offset_curve(self.font.leading)
+ line_offset = self.font.leading * self.font_scale
+ path = path.offset_curve(line_offset)
- def transform_glyphs(self, path, line):
- text_scale = Transform(f'scale({self.font_scale})')
+ def transform_glyphs(self, path, line, iterator):
text_width = line.bounding_box().width
- text_baseline = line.bounding_box(text_scale).bottom
+ text_baseline = line.bounding_box().bottom
+ backwards = self.settings.back_and_forth and iterator % 1 == 1
if self.text_position == 'stretch':
num_spaces = len(line) - 1
@@ -130,7 +142,7 @@ class TextAlongPath:
line_glyphs = [glyph for glyph in line.iterdescendants(SVG_GROUP_TAG) if glyph.get('inkstitch:letter-group', '') == 'glyph']
total_stretch_spaces = len(line_glyphs) - 1 + num_spaces
- stretch_space = (path.length - text_width * self.font_scale) / total_stretch_spaces
+ stretch_space = (path.length - text_width) / total_stretch_spaces
else:
stretch_space = 0
@@ -139,10 +151,14 @@ class TextAlongPath:
old_bbox = None
words = line.getchildren()
+ if backwards:
+ words.reverse()
if self.font.text_direction == "rtl":
words.reverse()
for word in words:
glyphs = word.getchildren()
+ if backwards:
+ glyphs.reverse()
if self.font.text_direction == "rtl":
glyphs.reverse()
for glyph in glyphs:
@@ -163,12 +179,16 @@ class TextAlongPath:
first = path.interpolate(distance)
last = path.interpolate(new_distance)
+ if not first or not last:
+ # unusable path, nothing we can do
+ continue
+
angle = degrees(atan2(last.y - first.y, last.x - first.x)) % 360
translate = InkstitchPoint(first.x, first.y) - InkstitchPoint(left, text_baseline)
transform = Transform(f"rotate({angle}, {first.x}, {first.y}) translate({translate.x} {translate.y})")
correction_transform = Transform(get_correction_transform(glyph))
- glyph.transform = correction_transform @ transform @ glyph.transform @ text_scale
+ glyph.transform = correction_transform @ transform @ glyph.transform
# set values for next iteration
distance = new_distance
@@ -177,7 +197,6 @@ class TextAlongPath:
distance += stretch_space
def get_start_position(self, text_length, path_length):
- text_length = text_length * self.font_scale
start_position = 0
if self.text_position == 'center':
start_position = (path_length - text_length) / 2
diff --git a/lib/lettering/utils.py b/lib/lettering/utils.py
index 0c649fa0..4c9822ea 100644
--- a/lib/lettering/utils.py
+++ b/lib/lettering/utils.py
@@ -38,7 +38,7 @@ def get_font_paths():
return font_paths
-def get_font_by_id(font_id):
+def get_font_by_id(font_id, show_font_path_warning=True):
font_paths = get_font_paths()
for font_path in font_paths:
try:
@@ -46,7 +46,7 @@ def get_font_by_id(font_id):
except OSError:
continue
for font_dir in font_dirs:
- font = _get_font_from_path(font_path, font_dir)
+ font = _get_font_from_path(font_path, font_dir, show_font_path_warning)
if font and font_id in [font.id, font.marked_custom_font_id]:
return font
return None
diff --git a/templates/lettering_along_path.xml b/templates/lettering_along_path.xml
index 98f12c38..9f13c365 100644
--- a/templates/lettering_along_path.xml
+++ b/templates/lettering_along_path.xml
@@ -26,13 +26,11 @@
<label appearance="header">This extension bends an Ink/Stitch text to a path.</label>
<label>Select Ink/Stitch text and a path before running this extension.</label>
<spacer />
- <label>The text needs to meet these conditions:</label>
- <label indent="1">* The text consists of only one line of text</label>
- <label indent="1">* The text should not be too large for the given path</label>
+ <label>⚠ The text width should not be longer than the path ⚠</label>
<spacer />
- <label>In the text position dropdown menu, you can decide how the text will be placed on the path.
- When stretch is selected, the spaces between the glyphs will be expanded, so that the text stretches over the entire path.
- </label>
+ <label>Text position:</label>
+ <label indent="1">Text can be positioned at the start, end or center of the path.</label>
+ <label indent="1">When stretch is selected, the spaces between the glyphs will be expanded, so that the text stretches over the entire path.</label>
<spacer />
<label>More information on our website</label>
<label appearance="url">https://inkstitch.org/docs/lettering/#lettering-along-path</label>