diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2024-10-21 17:01:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-21 17:01:58 +0200 |
| commit | c6fecfb0bc91d94f56da43e242b6e59b41058094 (patch) | |
| tree | 7d33e5a67d97461089ffb6f0dbfeb1fefa95cbd0 /lib/gui | |
| parent | dbfdb3e8d4fe3787927e8ab536473f9db6264e2b (diff) | |
Add color sort option for multicolor fonts (#3242)
Diffstat (limited to 'lib/gui')
| -rw-r--r-- | lib/gui/lettering/main_panel.py | 22 | ||||
| -rw-r--r-- | lib/gui/lettering/option_panel.py | 28 | ||||
| -rw-r--r-- | lib/gui/lettering_font_sample.py | 18 |
3 files changed, 50 insertions, 18 deletions
diff --git a/lib/gui/lettering/main_panel.py b/lib/gui/lettering/main_panel.py index 5393fcf3..06388dd0 100644 --- a/lib/gui/lettering/main_panel.py +++ b/lib/gui/lettering/main_panel.py @@ -81,7 +81,8 @@ class LetteringPanel(wx.Panel): "font": None, "scale": 100, "trim_option": 0, - "use_trim_symbols": False + "use_trim_symbols": False, + "color_sort": False }) if INKSTITCH_LETTERING in self.group.attrib: @@ -98,6 +99,7 @@ class LetteringPanel(wx.Panel): def apply_settings(self): """Make the settings in self.settings visible in the UI.""" + self.options_panel.color_sort_checkbox.SetValue(bool(self.settings.color_sort)) self.options_panel.back_and_forth_checkbox.SetValue(bool(self.settings.back_and_forth)) self.options_panel.trim_option_choice.SetSelection(self.settings.trim_option) self.options_panel.use_trim_symbols.SetValue(bool(self.settings.use_trim_symbols)) @@ -230,6 +232,14 @@ class LetteringPanel(wx.Panel): self.options_panel.back_and_forth_checkbox.Disable() self.options_panel.back_and_forth_checkbox.SetValue(False) + if font.sortable: + # The creator of the font allowed color sorting: "sortable": false + self.options_panel.color_sort_checkbox.Enable() + self.options_panel.color_sort_checkbox.SetValue(bool(self.settings.color_sort)) + else: + self.options_panel.color_sort_checkbox.Disable() + self.options_panel.color_sort_checkbox.SetValue(False) + self.options_panel.Layout() self.update_preview() @@ -279,15 +289,17 @@ class LetteringPanel(wx.Panel): # L10N The user has chosen to scale the text by some percentage # (50%, 200%, etc). If you need to use the percentage symbol, # make sure to double it (%%). - INKSCAPE_LABEL: _("Text scale %s%%") % self.settings.scale + INKSCAPE_LABEL: _("Text scale") + f' {self.settings.scale}%' }) self.group.append(destination_group) font = self.fonts.get(self.options_panel.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, use_trim_symbols=self.settings.use_trim_symbols) - + font.render_text( + self.settings.text, destination_group, back_and_forth=self.settings.back_and_forth, + trim_option=self.settings.trim_option, use_trim_symbols=self.settings.use_trim_symbols, + color_sort=self.settings.color_sort + ) except FontError as e: if raise_error: inkex.errormsg(_("Error: Text cannot be applied to the document.\n%s") % e) diff --git a/lib/gui/lettering/option_panel.py b/lib/gui/lettering/option_panel.py index e0c4388b..aea281ba 100644 --- a/lib/gui/lettering/option_panel.py +++ b/lib/gui/lettering/option_panel.py @@ -57,14 +57,16 @@ class LetteringOptionsPanel(wx.Panel): outer_sizer.Add(filter_sizer, 0, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 10) # options - self.options_box = wx.StaticBox(self, wx.ID_ANY, label=_("Options")) - self.scale_spinner = wx.SpinCtrl(self, wx.ID_ANY, min=0, max=1000, initial=100) self.scale_spinner.Bind(wx.EVT_SPINCTRL, lambda event: self.panel.on_change("scale", event)) self.back_and_forth_checkbox = wx.CheckBox(self, label=_("Stitch lines of text back and forth")) self.back_and_forth_checkbox.Bind(wx.EVT_CHECKBOX, lambda event: self.panel.on_change("back_and_forth", event)) + self.color_sort_checkbox = wx.CheckBox(self, label=_("Color sort")) + self.color_sort_checkbox.Bind(wx.EVT_CHECKBOX, lambda event: self.panel.on_change("color_sort", event)) + self.color_sort_checkbox.SetToolTip(_("Sort multicolor fonts. Unifies tartan patterns.")) + self.trim_option_choice = wx.Choice(self, choices=[_("Never"), _("after each line"), _("after each word"), _("after each letter")], name=_("Add trim command")) self.trim_option_choice.Bind(wx.EVT_CHOICE, lambda event: self.panel.on_trim_option_change(event)) @@ -74,22 +76,26 @@ class LetteringOptionsPanel(wx.Panel): self.use_trim_symbols.SetToolTip(_('Uses command symbols if enabled. When disabled inserts trim commands as params.')) left_option_sizer = wx.BoxSizer(wx.VERTICAL) - left_option_sizer.Add(self.back_and_forth_checkbox, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 5) - - trim_option_sizer = wx.BoxSizer(wx.HORIZONTAL) - trim_option_sizer.Add(wx.StaticText(self, wx.ID_ANY, _("Add trims")), 0, wx.LEFT | wx.ALIGN_TOP, 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) font_scale_sizer.Add(wx.StaticText(self, wx.ID_ANY, _("Scale")), 0, wx.LEFT | wx.ALIGN_CENTRE_VERTICAL, 0) font_scale_sizer.Add(self.scale_spinner, 0, wx.LEFT, 10) font_scale_sizer.Add(wx.StaticText(self, wx.ID_ANY, "%"), 0, wx.LEFT | wx.ALIGN_CENTRE_VERTICAL, 3) + left_option_sizer.Add(font_scale_sizer, 0, wx.ALIGN_LEFT, 5) + left_option_sizer.Add(self.back_and_forth_checkbox, 1, wx.LEFT | wx.TOP | wx.RIGHT, 5) + left_option_sizer.Add(self.color_sort_checkbox, 1, wx.LEFT | wx.TOP | wx.RIGHT, 5) + + right_option_sizer = wx.BoxSizer(wx.VERTICAL) + + right_option_sizer.Add(wx.StaticText(self, wx.ID_ANY, _("Add trims")), 0, wx.LEFT | wx.ALIGN_TOP, 5) + right_option_sizer.Add(self.trim_option_choice, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT | wx.BOTTOM, 5) + right_option_sizer.Add(self.use_trim_symbols, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT | wx.BOTTOM, 5) + + self.options_box = wx.StaticBox(self, wx.ID_ANY, label=_("Options")) options_sizer = wx.StaticBoxSizer(self.options_box, wx.HORIZONTAL) - options_sizer.Add(left_option_sizer, 1, wx.EXPAND, 10) - options_sizer.Add(font_scale_sizer, 0, wx.RIGHT, 10) + options_sizer.Add(left_option_sizer, 1, wx.LEFT | wx.RIGHT, 10) + options_sizer.Add(right_option_sizer, 0, wx.RIGHT, 10) outer_sizer.Add(options_sizer, 0, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 10) # text input diff --git a/lib/gui/lettering_font_sample.py b/lib/gui/lettering_font_sample.py index e5312c7e..984f6356 100644 --- a/lib/gui/lettering_font_sample.py +++ b/lib/gui/lettering_font_sample.py @@ -36,7 +36,7 @@ class FontSampleFrame(wx.Frame): self.font_chooser = wx.adv.BitmapComboBox(self.settings, wx.ID_ANY, style=wx.CB_READONLY | wx.CB_SORT, size=((800, 20))) self.font_chooser.Bind(wx.EVT_COMBOBOX, self.on_font_changed) - grid_settings_sizer = wx.FlexGridSizer(6, 2, 5, 5) + grid_settings_sizer = wx.FlexGridSizer(7, 2, 5, 5) grid_settings_sizer.AddGrowableCol(1) direction_label = wx.StaticText(self.settings, label=_("Stitch direction")) @@ -45,6 +45,7 @@ class FontSampleFrame(wx.Frame): self.scale_spinner = wx.SpinCtrl(self.settings, wx.ID_ANY, min=0, max=1000, initial=100) max_line_width_label = wx.StaticText(self.settings, label=_("Max. line width")) self.max_line_width = wx.SpinCtrl(self.settings, wx.ID_ANY, min=0, max=5000, initial=180) + self.color_sort_checkbox = wx.CheckBox(self.settings, label=_("Color sort")) grid_settings_sizer.Add(direction_label, 0, wx.ALIGN_LEFT, 0) grid_settings_sizer.Add(self.direction, 0, wx.EXPAND, 0) @@ -52,6 +53,8 @@ class FontSampleFrame(wx.Frame): grid_settings_sizer.Add(self.scale_spinner, 0, wx.EXPAND, 0) grid_settings_sizer.Add(max_line_width_label, 0, wx.ALIGN_LEFT, 0) grid_settings_sizer.Add(self.max_line_width, 0, wx.EXPAND, 0) + grid_settings_sizer.Add(wx.StaticText(), 0, wx.ALIGN_LEFT, 0) + grid_settings_sizer.Add(self.color_sort_checkbox, 0, wx.EXPAND, 0) apply_sizer = wx.BoxSizer(wx.HORIZONTAL) self.cancel_button = wx.Button(self.settings, label=_("Cancel")) @@ -127,6 +130,10 @@ class FontSampleFrame(wx.Frame): for variant in font.has_variants(): self.direction.Append(variant) self.direction.SetSelection(0) + if font.sortable: + self.color_sort_checkbox.Enable() + else: + self.color_sort_checkbox.Disable() def apply(self, event): # apply scale to layer and extract for later use @@ -142,6 +149,7 @@ class FontSampleFrame(wx.Frame): # parameters line_width = self.max_line_width.GetValue() direction = self.direction.GetValue() + color_sort = self.sortable(font) font._load_variants() font_variant = font.variants[direction] @@ -192,9 +200,15 @@ class FontSampleFrame(wx.Frame): width += width_to_add # render text and close - font.render_text(text, self.layer, variant=direction, back_and_forth=False) + font.render_text(text, self.layer, variant=direction, back_and_forth=False, color_sort=color_sort) self.GetTopLevelParent().Close() + def sortable(self, font): + color_sort = self.color_sort_checkbox.GetValue() + if color_sort and not font.sortable: + color_sort = False + return color_sort + def duplicate_warning(self, font): # warn about duplicated glyphs if len(set(font.available_glyphs)) != len(font.available_glyphs): |
