lettering tools: remember last font (#3498)

pull/3504/head
Kaalleen 2025-02-11 18:52:01 +01:00 zatwierdzone przez GitHub
rodzic b7f5e94fd2
commit cee9aa0d1d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
5 zmienionych plików z 30 dodań i 9 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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))

Wyświetl plik

@ -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]

Wyświetl plik

@ -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:

Wyświetl plik

@ -30,6 +30,10 @@ DEFAULT_SETTINGS = {
"last_applied_palette": "",
# sew stack editor
"stitch_layer_editor_sash_position": -200,
# lettering (all lettering applications)
"last_font": "Ink/Stitch Small Font",
# font sampling
"font_sampling_max_line_width": 180
}