diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2025-02-11 18:52:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-11 18:52:01 +0100 |
| commit | cee9aa0d1d6f0173643e6480b4e11fc1f27f0ffb (patch) | |
| tree | 249897ecbc6942e404088a22fd7e7dd822896b60 /lib/gui | |
| parent | b7f5e94fd2c39bf386fe116ac172402ca99dce5e (diff) | |
lettering tools: remember last font (#3498)
Diffstat (limited to 'lib/gui')
| -rw-r--r-- | lib/gui/edit_json/main_panel.py | 16 | ||||
| -rw-r--r-- | lib/gui/lettering/main_panel.py | 6 | ||||
| -rw-r--r-- | lib/gui/lettering_font_sample.py | 9 | ||||
| -rw-r--r-- | lib/gui/simulator/drawing_panel.py | 4 |
4 files changed, 26 insertions, 9 deletions
diff --git a/lib/gui/edit_json/main_panel.py b/lib/gui/edit_json/main_panel.py index b175f892..8b896629 100644 --- a/lib/gui/edit_json/main_panel.py +++ b/lib/gui/edit_json/main_panel.py @@ -20,6 +20,7 @@ from ...lettering.font_variant import FontVariant from ...lettering.categories import FONT_CATEGORIES from ...stitch_plan import stitch_groups_to_stitch_plan from ...svg.tags import SVG_PATH_TAG +from ...utils.settings import global_settings from ...utils.threading import ExitThread, check_stop_flag from .. import PreviewRenderer from . import HelpPanel, SettingsPanel @@ -69,7 +70,8 @@ class LetteringEditJsonPanel(wx.Panel): self.SetSizer(notebook_sizer) self.set_font_list() - self.settings_panel.font_chooser.SetValue(list(self.fonts.values())[0].marked_custom_font_name) + select_font = global_settings['last_font'] + self.settings_panel.font_chooser.SetValue(select_font) self.on_font_changed() self.SetSizeHints(notebook_sizer.CalcMin()) @@ -229,6 +231,7 @@ class LetteringEditJsonPanel(wx.Panel): def on_font_changed(self, event=None): self.font = self.fonts.get(self.settings_panel.font_chooser.GetValue(), list(self.fonts.values())[0].marked_custom_font_name) + global_settings['last_font'] = self.font.marked_custom_font_name self.kerning_pairs = self.font.kerning_pairs self.font._load_variants() self.default_variant = self.font.variants[self.font.json_default_variant] @@ -305,7 +308,10 @@ class LetteringEditJsonPanel(wx.Panel): self.settings_panel.font_kerning.size.SetValue(self.font.size) self.settings_panel.font_kerning.max_scale.SetValue(self.font.max_scale) self.settings_panel.font_kerning.min_scale.SetValue(self.font.min_scale) - self.settings_panel.font_kerning.horiz_adv_x_default.SetValue(self.font.horiz_adv_x_default) + if self.font.horiz_adv_x_default is None: + self.settings_panel.font_kerning.horiz_adv_x_default.SetValue(0.0) + else: + self.settings_panel.font_kerning.horiz_adv_x_default.SetValue(self.font.horiz_adv_x_default) self.settings_panel.font_kerning.horiz_adv_x_space.SetValue(self.font.word_spacing) def update_kerning_list(self): @@ -358,6 +364,10 @@ class LetteringEditJsonPanel(wx.Panel): with open(json_file, 'r') as font_data: data = json.load(font_data) + horiz_adv_x_default = self.font_meta['horiz_adv_x_default'] + if horiz_adv_x_default == 0: + horiz_adv_x_default = None + for key, val in self.font_meta.items(): data[key] = val horiz_adv_x = {key: val for key, val in self.horiz_adv_x.items() if val != self.font_meta['horiz_adv_x_default']} @@ -445,7 +455,7 @@ class LetteringEditJsonPanel(wx.Panel): node.set('transform', transform) horiz_adv_x_default = self.font_meta['horiz_adv_x_default'] - if horiz_adv_x_default is None: + if horiz_adv_x_default in [0, None]: horiz_adv_x_default = glyph.width + glyph.min_x position_x += self.font.horiz_adv_x.get(character, horiz_adv_x_default) - glyph.min_x diff --git a/lib/gui/lettering/main_panel.py b/lib/gui/lettering/main_panel.py index 6bb7219e..67e0db7f 100644 --- a/lib/gui/lettering/main_panel.py +++ b/lib/gui/lettering/main_panel.py @@ -17,14 +17,13 @@ from ...lettering.categories import FONT_CATEGORIES from ...stitch_plan import stitch_groups_to_stitch_plan from ...svg.tags import INKSTITCH_LETTERING from ...utils import DotDict, cache +from ...utils.settings import global_settings from ...utils.threading import ExitThread, check_stop_flag from .. import PresetsPanel, PreviewRenderer, info_dialog from . import LetteringHelpPanel, LetteringOptionsPanel class LetteringPanel(wx.Panel): - DEFAULT_FONT = "small_font" - def __init__(self, parent, simulator, group, metadata=None, background_color='white'): self.parent = parent self.simulator = simulator @@ -186,7 +185,7 @@ class LetteringPanel(wx.Panel): @property def default_font(self): try: - return self.fonts_by_id[self.DEFAULT_FONT] + return self.fonts[global_settings['last_font']] except KeyError: return list(self.fonts.values())[0] @@ -210,6 +209,7 @@ class LetteringPanel(wx.Panel): def on_font_changed(self, event=None): font = self.fonts.get(self.options_panel.font_chooser.GetValue(), self.default_font) self.settings.font = font.marked_custom_font_id + global_settings['last_font'] = font.marked_custom_font_name filter_size = self.options_panel.font_size_filter.GetValue() self.options_panel.scale_spinner.SetRange(int(font.min_scale * 100), int(font.max_scale * 100)) diff --git a/lib/gui/lettering_font_sample.py b/lib/gui/lettering_font_sample.py index e5ce312d..3335a830 100644 --- a/lib/gui/lettering_font_sample.py +++ b/lib/gui/lettering_font_sample.py @@ -11,6 +11,7 @@ from inkex import Group, errormsg from ..i18n import _ from ..lettering import get_font_list +from ..utils.settings import global_settings class FontSampleFrame(wx.Frame): @@ -106,7 +107,10 @@ class FontSampleFrame(wx.Frame): self.main_panel.SetSizer(notebook_sizer) self.set_font_list() - self.font_chooser.SetValue(list(self.fonts.values())[0].marked_custom_font_name) + select_font = global_settings['last_font'] + self.font_chooser.SetValue(select_font) + max_line_width = global_settings['font_sampling_max_line_width'] + self.max_line_width.SetValue(max_line_width) self.on_font_changed() self.SetSizeHints(notebook_sizer.CalcMin()) @@ -129,6 +133,7 @@ class FontSampleFrame(wx.Frame): def on_font_changed(self, event=None): self.font = self.fonts.get(self.font_chooser.GetValue(), list(self.fonts.values())[0].marked_custom_font_name) + global_settings['last_font'] = self.font.marked_custom_font_name self.scale_spinner.SetRange(int(self.font.min_scale * 100), int(self.font.max_scale * 100)) # font._load_variants() self.direction.Clear() @@ -155,6 +160,8 @@ class FontSampleFrame(wx.Frame): line_width = self.max_line_width.GetValue() direction = self.direction.GetValue() + global_settings['font_sampling_max_line_width'] = line_width + self.font._load_variants() self.font_variant = self.font.variants[direction] diff --git a/lib/gui/simulator/drawing_panel.py b/lib/gui/simulator/drawing_panel.py index 1587ecfa..4a07bfd7 100644 --- a/lib/gui/simulator/drawing_panel.py +++ b/lib/gui/simulator/drawing_panel.py @@ -186,13 +186,13 @@ class DrawingPanel(wx.Panel): if len(stitches) > 1: self.draw_stitch_lines(canvas, pen, stitches, jumps) self.draw_needle_penetration_points(canvas, pen, stitches) - last_stitch = stitches[-1] + last_stitch = stitches[-1] else: stitches = stitches[:int(self.current_stitch) - stitch] if len(stitches) > 1: self.draw_stitch_lines(canvas, pen, stitches, jumps) self.draw_needle_penetration_points(canvas, pen, stitches) - last_stitch = stitches[-1] + last_stitch = stitches[-1] break if last_stitch: |
