kopia lustrzana https://github.com/inkstitch/inkstitch
Fix lettering along path when glyphs have subgroups (#2754)
* remove "use no commands" restriction for lettering along pathpull/2762/head^2
rodzic
d43f2e2ff9
commit
f6a0b2eeeb
|
@ -237,7 +237,8 @@ class EmbroideryElement(object):
|
|||
@param('force_lock_stitches',
|
||||
_('Force lock stitches'),
|
||||
tooltip=_('Sew lock stitches after sewing this element, '
|
||||
'even if the distance to the next object is shorter than defined by the Minimum jump stitch length value in the Ink/Stitch preferences.'),
|
||||
'even if the distance to the next object is shorter than defined by the '
|
||||
'minimum jump stitch length value in the Ink/Stitch preferences.'),
|
||||
type='boolean',
|
||||
default=False,
|
||||
sort_index=51)
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
||||
|
||||
import json
|
||||
import sys
|
||||
from math import atan2, degrees
|
||||
|
||||
from inkex import Boolean, Transform, errormsg
|
||||
|
@ -32,19 +31,25 @@ class LetteringAlongPath(InkstitchExtension):
|
|||
def effect(self):
|
||||
# we ignore everything but the first path/text
|
||||
text, path = self.get_selection()
|
||||
self.load_settings(text)
|
||||
if text is None or path is None:
|
||||
errormsg(_("Please select one path and one Ink/Stitch lettering group."))
|
||||
return
|
||||
|
||||
glyphs = [glyph for glyph in text.iterdescendants(SVG_GROUP_TAG) if len(glyph.label) == 1]
|
||||
glyphs = [glyph for glyph in text.iterdescendants(SVG_GROUP_TAG) if glyph.label and len(glyph.label) == 1]
|
||||
if not glyphs:
|
||||
errormsg(_("The text doesn't contain any glyphs."))
|
||||
sys.exit(1)
|
||||
return
|
||||
|
||||
self.load_settings(text)
|
||||
path = Stroke(path).as_multi_line_string().geoms[0]
|
||||
path_length = path.length
|
||||
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)
|
||||
|
||||
# overall bounding box - get from direct glyph parent
|
||||
def get_position_and_stretch_values(self, path, text, glyphs):
|
||||
text_bbox = glyphs[0].getparent().bounding_box()
|
||||
text_y = text_bbox.bottom
|
||||
text_baseline = text_bbox.bottom
|
||||
|
||||
if self.options.stretch_spaces:
|
||||
text_content = self.settings["text"]
|
||||
|
@ -53,6 +58,7 @@ class LetteringAlongPath(InkstitchExtension):
|
|||
text_width = convert_unit(text_bbox.width, 'px', self.svg.unit)
|
||||
|
||||
if len(text_content) - 1 != 0:
|
||||
path_length = path.length
|
||||
stretch_space = (path_length - text_width) / (len(text_content) - 1)
|
||||
else:
|
||||
stretch_space = 0
|
||||
|
@ -60,9 +66,23 @@ class LetteringAlongPath(InkstitchExtension):
|
|||
stretch_space = 0
|
||||
space_indices = []
|
||||
|
||||
self.transform_glyphs(glyphs, path, stretch_space, space_indices, text_y)
|
||||
return space_indices, stretch_space, text_baseline
|
||||
|
||||
def transform_glyphs(self, glyphs, path, stretch_space, space_indices, text_y):
|
||||
def hide_commands(self, glyphs):
|
||||
# hide commmands for bounding box calculation
|
||||
hidden_commands = []
|
||||
for glyph in glyphs:
|
||||
for group in glyph.iterdescendants(SVG_GROUP_TAG):
|
||||
if group.get_id().startswith("command_group") and group.style('display', 'inline') != 'none':
|
||||
hidden_commands.append(group)
|
||||
group.style['display'] = 'none'
|
||||
return hidden_commands
|
||||
|
||||
def restore_commands(self, hidden_commands):
|
||||
for command in hidden_commands:
|
||||
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})')
|
||||
distance = 0
|
||||
old_bbox = None
|
||||
|
@ -91,7 +111,7 @@ class LetteringAlongPath(InkstitchExtension):
|
|||
last = path.interpolate(new_distance)
|
||||
|
||||
angle = degrees(atan2(last.y - first.y, last.x - first.x)) % 360
|
||||
translate = InkstitchPoint(first.x, first.y) - InkstitchPoint(left, text_y)
|
||||
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))
|
||||
|
@ -140,7 +160,6 @@ class LetteringAlongPath(InkstitchExtension):
|
|||
paths.append(node)
|
||||
|
||||
if not groups or not paths:
|
||||
errormsg(_("Please select one path and one Ink/Stitch lettering group."))
|
||||
sys.exit(1)
|
||||
return [None, None]
|
||||
|
||||
return [groups[0], paths[0]]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
./pyembroidery
|
||||
|
||||
# get up to date inkex version (Febuary 10, 2024)
|
||||
inkex @ git+https://gitlab.com/inkscape/extensions.git@99db88135c3e557b343dd3d878eea8de2676d2ab
|
||||
inkex @ git+https://gitlab.com/inkscape/extensions.git@8d51d7449d73096382c2f39e726eddc4f9bbcfc4
|
||||
|
||||
wxPython>=4.1.1
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
<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 indent="1">* Text text should not contain trim symbols</label>
|
||||
<spacer />
|
||||
<label>The stretch option defines whether the spaces between glyphs should be expanded so that the text stretches over the entire path.</label>
|
||||
</page>
|
||||
|
|
Ładowanie…
Reference in New Issue