lettering: add option to chose between trim command styles (#2110)

pull/2121/head dev-build-kaalleen-select_elements-fill-method
Kaalleen 2023-03-07 20:08:21 +01:00 zatwierdzone przez GitHub
rodzic 5cd11f7416
commit 9e6a70f76e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 21 dodań i 11 usunięć

Wyświetl plik

@ -76,6 +76,10 @@ class LetteringFrame(wx.Frame):
name=_("Add trim command"))
self.trim_option_choice.Bind(wx.EVT_CHOICE, lambda event: self.on_trim_option_change(event))
self.use_trim_symbols = wx.CheckBox(self, label=_("Use command symbols"))
self.use_trim_symbols.Bind(wx.EVT_CHECKBOX, lambda event: self.on_change("use_trim_symbols", event))
self.use_trim_symbols.SetToolTip(_('Uses command symbols if enabled. When disabled inserts trim commands as params.'))
# text editor
self.text_input_box = wx.StaticBox(self, wx.ID_ANY, label=_("Text"))
@ -108,7 +112,8 @@ class LetteringFrame(wx.Frame):
"back_and_forth": False,
"font": None,
"scale": 100,
"trim_option": 0
"trim_option": 0,
"use_trim_symbols": False
})
if INKSTITCH_LETTERING in self.group.attrib:
@ -127,6 +132,7 @@ class LetteringFrame(wx.Frame):
"""Make the settings in self.settings visible in the UI."""
self.back_and_forth_checkbox.SetValue(bool(self.settings.back_and_forth))
self.trim_option_choice.SetSelection(self.settings.trim_option)
self.use_trim_symbols.SetValue(bool(self.settings.use_trim_symbols))
self.set_initial_font(self.settings.font)
self.text_editor.SetValue(self.settings.text)
self.scale_spinner.SetValue(self.settings.scale)
@ -315,7 +321,7 @@ class LetteringFrame(wx.Frame):
font = self.fonts.get(self.font_chooser.GetValue(), self.default_font)
try:
font.render_text(self.settings.text, destination_group, back_and_forth=self.settings.back_and_forth,
trim_option=self.settings.trim_option)
trim_option=self.settings.trim_option, use_trim_symbols=self.settings.use_trim_symbols)
except FontError as e:
if raise_error:
@ -408,6 +414,7 @@ class LetteringFrame(wx.Frame):
trim_option_sizer = wx.BoxSizer(wx.HORIZONTAL)
trim_option_sizer.Add(wx.StaticText(self, wx.ID_ANY, "Add trims"), 0, wx.LEFT | wx.ALIGN_CENTRE_VERTICAL, 5)
trim_option_sizer.Add(self.trim_option_choice, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT | wx.BOTTOM, 5)
trim_option_sizer.Add(self.use_trim_symbols, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT | wx.BOTTOM, 5)
left_option_sizer.Add(trim_option_sizer, 0, wx.ALIGN_LEFT, 5)
font_scale_sizer = wx.BoxSizer(wx.HORIZONTAL)

Wyświetl plik

@ -19,7 +19,7 @@ from ..marker import MARKER, ensure_marker, has_marker
from ..stitches.auto_satin import auto_satin
from ..svg.tags import (CONNECTION_END, CONNECTION_START, EMBROIDERABLE_TAGS,
INKSCAPE_LABEL, SVG_GROUP_TAG, SVG_PATH_TAG,
SVG_USE_TAG, XLINK_HREF)
SVG_USE_TAG, XLINK_HREF, INKSTITCH_ATTRIBS)
from ..utils import Point
from .font_variant import FontVariant
@ -184,7 +184,7 @@ class Font(object):
def is_custom_font(self):
return get_custom_font_dir() in self.path
def render_text(self, text, destination_group, variant=None, back_and_forth=True, trim_option=0):
def render_text(self, text, destination_group, variant=None, back_and_forth=True, trim_option=0, use_trim_symbols=False):
"""Render text into an SVG group element."""
self._load_variants()
@ -226,7 +226,7 @@ class Font(object):
element.set('style', '%s' % style.to_str())
# add trims
self._add_trims(destination_group, text, trim_option, back_and_forth)
self._add_trims(destination_group, text, trim_option, use_trim_symbols, back_and_forth)
# make sure necessary marker and command symbols are in the defs section
self._ensure_command_symbols(destination_group)
self._ensure_marker_symbols(destination_group)
@ -340,7 +340,7 @@ class Font(object):
c.set(CONNECTION_END, "#%s" % new_element_id)
c.set(CONNECTION_START, "#%s" % new_symbol_id)
def _add_trims(self, destination_group, text, trim_option, back_and_forth):
def _add_trims(self, destination_group, text, trim_option, use_trim_symbols, back_and_forth):
"""
trim_option == 0 --> no trims
trim_option == 1 --> trim at the end of each line
@ -369,15 +369,15 @@ class Font(object):
# letter
if trim_option == 3:
self._process_trim(group)
self._process_trim(group, use_trim_symbols)
# word
elif trim_option == 2 and i+1 in space_indices + line_break_indices:
self._process_trim(group)
self._process_trim(group, use_trim_symbols)
# line
elif trim_option == 1 and i+1 in line_break_indices:
self._process_trim(group)
self._process_trim(group, use_trim_symbols)
def _process_trim(self, group):
def _process_trim(self, group, use_trim_symbols):
# find the last path that does not carry a marker and add a trim there
for path_child in group.iterdescendants(EMBROIDERABLE_TAGS):
if not has_marker(path_child):
@ -390,7 +390,10 @@ class Font(object):
if element.shape:
element_id = "%s_%s" % (element.node.get('id'), randint(0, 9999))
element.node.set("id", element_id)
add_commands(element, ['trim'])
if use_trim_symbols is False:
element.node.set(INKSTITCH_ATTRIBS['trim_after'], 'true')
else:
add_commands(element, ['trim'])
def _ensure_command_symbols(self, group):
# collect commands