kopia lustrzana https://github.com/inkstitch/inkstitch
implement trim option for lettering
rodzic
53a9bd6b31
commit
602f201cb6
|
@ -254,7 +254,12 @@ def symbol_defs():
|
|||
|
||||
@cache
|
||||
def get_defs(document):
|
||||
return document.find(SVG_DEFS_TAG)
|
||||
defs = document.find(SVG_DEFS_TAG)
|
||||
|
||||
if defs is None:
|
||||
defs = inkex.etree.SubElement(document, SVG_DEFS_TAG)
|
||||
|
||||
return defs
|
||||
|
||||
|
||||
def ensure_symbol(document, command):
|
||||
|
|
|
@ -2,12 +2,8 @@ import sys
|
|||
|
||||
import inkex
|
||||
|
||||
from ..commands import add_commands
|
||||
from ..elements import SatinColumn
|
||||
from ..i18n import _
|
||||
from ..stitches.auto_satin import auto_satin
|
||||
from ..svg import get_correction_transform
|
||||
from ..svg.tags import SVG_GROUP_TAG, INKSCAPE_LABEL
|
||||
from .commands import CommandsExtension
|
||||
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ class LetteringFrame(wx.Frame):
|
|||
|
||||
self.back_and_forth_checkbox = wx.CheckBox(self, label=_("Stitch lines of text back and forth"))
|
||||
self.back_and_forth_checkbox.SetValue(self.settings.back_and_forth)
|
||||
self.Bind(wx.EVT_CHECKBOX, lambda event: self.on_change("back_and_forth", event))
|
||||
self.back_and_forth_checkbox.Bind(wx.EVT_CHECKBOX, lambda event: self.on_change("back_and_forth", event))
|
||||
|
||||
self.trim_checkbox = wx.CheckBox(self, label=_("Add trims"))
|
||||
self.trim_checkbox.SetValue(bool(self.settings.trim))
|
||||
self.Bind(wx.EVT_CHECKBOX, lambda event: self.on_change("trim", event))
|
||||
self.trim_checkbox.Bind(wx.EVT_CHECKBOX, lambda event: self.on_change("trim", event))
|
||||
|
||||
# text editor
|
||||
self.text_editor_box = wx.StaticBox(self, wx.ID_ANY, label=_("Text"))
|
||||
|
@ -94,7 +94,8 @@ class LetteringFrame(wx.Frame):
|
|||
def update_lettering(self):
|
||||
font_path = os.path.join(get_bundled_dir("fonts"), self.settings.font)
|
||||
font = Font(font_path)
|
||||
self.group[:] = font.render_text(self.settings.text, back_and_forth=self.settings.back_and_forth, trim=self.settings.trim)
|
||||
del self.group[:]
|
||||
font.render_text(self.settings.text, self.group, back_and_forth=self.settings.back_and_forth, trim=self.settings.trim)
|
||||
|
||||
def generate_patches(self, abort_early=None):
|
||||
patches = []
|
||||
|
@ -155,7 +156,8 @@ class LetteringFrame(wx.Frame):
|
|||
outer_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
options_sizer = wx.StaticBoxSizer(self.options_box, wx.VERTICAL)
|
||||
options_sizer.Add(self.back_and_forth_checkbox, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT | wx.BOTTOM, 10)
|
||||
options_sizer.Add(self.back_and_forth_checkbox, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 5)
|
||||
options_sizer.Add(self.trim_checkbox, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT | wx.BOTTOM, 5)
|
||||
outer_sizer.Add(options_sizer, 0, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 10)
|
||||
|
||||
text_editor_sizer = wx.StaticBoxSizer(self.text_editor_box, wx.VERTICAL)
|
||||
|
|
|
@ -81,7 +81,9 @@ class Font(object):
|
|||
kerning_pairs = font_metadata('kerning_pairs', {})
|
||||
auto_satin = font_metadata('auto_satin', True)
|
||||
|
||||
def render_text(self, text, variant=None, back_and_forth=True, trim=False):
|
||||
def render_text(self, text, destination_group, variant=None, back_and_forth=True, trim=False):
|
||||
"""Render text into an SVG group element."""
|
||||
|
||||
if variant is None:
|
||||
variant = self.default_variant
|
||||
|
||||
|
@ -90,9 +92,6 @@ class Font(object):
|
|||
else:
|
||||
glyph_sets = [self.get_variant(variant)] * 2
|
||||
|
||||
line_group = inkex.etree.Element(SVG_GROUP_TAG, {
|
||||
INKSCAPE_LABEL: _("Ink/Stitch Text")
|
||||
})
|
||||
position = Point(0, 0)
|
||||
for i, line in enumerate(text.splitlines()):
|
||||
glyph_set = glyph_sets[i % 2]
|
||||
|
@ -101,15 +100,15 @@ class Font(object):
|
|||
letter_group = self._render_line(line, position, glyph_set)
|
||||
if glyph_set.variant == FontVariant.RIGHT_TO_LEFT:
|
||||
letter_group[:] = reversed(letter_group)
|
||||
line_group.append(letter_group)
|
||||
destination_group.append(letter_group)
|
||||
|
||||
position.x = 0
|
||||
position.y += self.leading
|
||||
|
||||
if self.auto_satin and len(line_group) > 0:
|
||||
self._apply_auto_satin(line_group)
|
||||
if self.auto_satin and len(destination_group) > 0:
|
||||
self._apply_auto_satin(destination_group, trim)
|
||||
|
||||
return line_group
|
||||
return destination_group
|
||||
|
||||
def get_variant(self, variant):
|
||||
return self.variants.get(variant, self.variants[self.default_variant])
|
||||
|
@ -174,7 +173,7 @@ class Font(object):
|
|||
|
||||
return node
|
||||
|
||||
def _apply_auto_satin(self, group):
|
||||
def _apply_auto_satin(self, group, trim):
|
||||
"""Apply Auto-Satin to an SVG XML node tree with an svg:g at its root.
|
||||
|
||||
The group's contents will be replaced with the results of the auto-
|
||||
|
@ -182,4 +181,4 @@ class Font(object):
|
|||
"""
|
||||
|
||||
elements = nodes_to_elements(group.iterdescendants(SVG_PATH_TAG))
|
||||
auto_satin(elements, preserve_order=True)
|
||||
auto_satin(elements, preserve_order=True, trim=trim)
|
||||
|
|
Ładowanie…
Reference in New Issue