Lettering: add font size filter (#1854)

* auto-update scale on font selection with an active filter
pull/1890/head
Kaalleen 2022-10-23 09:17:17 +02:00 zatwierdzone przez GitHub
rodzic 11cde9062e
commit 27d2fcecaa
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
51 zmienionych plików z 23907 dodań i 23808 usunięć

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 1,
"max_scale": 2.5,
"size": 40,
"horiz_adv_x_default": 66,
"horiz_adv_x_space": 20,
"units_per_em": 144,

Wyświetl plik

@ -5,6 +5,7 @@
"reversible": false,
"letter_case": "",
"default_glyph": " ",
"size": 14,
"min_scale": 0.75,
"max_scale": 2.0,
"horiz_adv_x_default": 43,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 1.6,
"size": 25.3,
"horiz_adv_x_default": 0,
"horiz_adv_x_space": 24,
"units_per_em": 113,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.25,
"max_scale": 0.55,
"size": 25.3,
"horiz_adv_x_default": 0,
"horiz_adv_x_space": 24,
"units_per_em": 113,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 1.3,
"size": 60,
"horiz_adv_x_default": 234,
"horiz_adv_x_space": 53,
"units_per_em": 212,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 0.6,
"max_scale": 1.5,
"size": 20,
"horiz_adv_x_default": 48,
"horiz_adv_x_space": 20,
"units_per_em": 100,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 1.5,
"size": 22.3,
"horiz_adv_x_default": 93,
"horiz_adv_x_space": 37,
"units_per_em": 162,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 0.8,
"max_scale": 1.8,
"size": 40,
"horiz_adv_x_default": 44,
"horiz_adv_x_space": 20,
"units_per_em": 227,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 1.3,
"size": 75,
"horiz_adv_x_default": 234,
"horiz_adv_x_space": 53,
"units_per_em": 212,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 1.5,
"size": 38.3,
"horiz_adv_x_default": 212,
"horiz_adv_x_space": 54,
"units_per_em": 200,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.9,
"max_scale": 1.1,
"size": 22,
"horiz_adv_x_default": 64,
"horiz_adv_x_space": 34,
"units_per_em": 136,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 1.5,
"size": 19.8,
"horiz_adv_x_default": 65,
"horiz_adv_x_space": 24,
"units_per_em": 87,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 1,
"max_scale": 2,
"size": 16,
"horiz_adv_x_default": 47,
"horiz_adv_x_space": 37,
"units_per_em": 47,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "_",
"min_scale": 0.5,
"max_scale": 3.0,
"size": 18,
"horiz_adv_x_default": null,
"horiz_adv_x_space": 20,
"units_per_em": 100,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": " ",
"min_scale": 0.7,
"max_scale": 1.4,
"size": 48.5,
"horiz_adv_x_default": 165,
"horiz_adv_x_space": 90,
"units_per_em": 200,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 0.9,
"max_scale": 1.2,
"size": 100,
"horiz_adv_x_default": 320,
"horiz_adv_x_space": 120,
"units_per_em": 400,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 2.0,
"size": 16.2,
"horiz_adv_x_default": 45,
"horiz_adv_x_space": 22,
"units_per_em": 100,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.25,
"max_scale": 0.55,
"size": 16.2,
"horiz_adv_x_default": 45,
"horiz_adv_x_space": 22,
"units_per_em": 100,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 0.8,
"max_scale": 1.4,
"size": 20,
"horiz_adv_x_default": 40,
"horiz_adv_x_space": 20,
"units_per_em": 81,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 0.8,
"max_scale": 2.0,
"size": 100,
"horiz_adv_x_default": null,
"horiz_adv_x_space": 100,
"units_per_em": 400,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": "<22>",
"min_scale": 0.7,
"max_scale": 2.0,
"size": 10.5,
"horiz_adv_x_default": null,
"horiz_adv_x_space": 30,
"units_per_em": 60,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": "<22>",
"min_scale": 0.7,
"max_scale": 2.0,
"size": 8,
"horiz_adv_x_default": null,
"horiz_adv_x_space": 34,
"units_per_em": 60,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": " ",
"min_scale": 0.4,
"max_scale": 1.5,
"size": 5.6,
"horiz_adv_x_default": 20,
"horiz_adv_x_space": 10,
"units_per_em": 32,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 0.6,
"max_scale": 1.4,
"size": 35,
"horiz_adv_x_default": 62,
"horiz_adv_x_space": 40,
"units_per_em": 173,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": " ",
"min_scale": 0.25,
"max_scale": 0.55,
"size": 35,
"horiz_adv_x_default": 62,
"horiz_adv_x_space": 40,
"units_per_em": 173,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 0.7,
"max_scale": 2,
"size": 70,
"horiz_adv_x_default": 0,
"horiz_adv_x_space": 55,
"units_per_em": 250,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 2,
"size": 29,
"horiz_adv_x_default": 78,
"horiz_adv_x_space": 26,
"units_per_em": 113,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.9,
"max_scale": 2.0,
"size": 12,
"horiz_adv_x_default": 38,
"horiz_adv_x_space": 24,
"units_per_em": 100,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 1.5,
"size": 19.8,
"horiz_adv_x_default": 50,
"horiz_adv_x_space": 21,
"units_per_em": 100,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 1.2,
"size": 20,
"horiz_adv_x_default": 55,
"horiz_adv_x_space": 22,
"units_per_em": 100,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.7,
"max_scale": 1.4,
"size": 35,
"horiz_adv_x_default": 105,
"horiz_adv_x_space": 39,
"units_per_em": 125,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 0.7,
"max_scale": 5.0,
"size": 36,
"horiz_adv_x_default": 136,
"horiz_adv_x_space": 30,
"units_per_em": 136,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": "<22>",
"min_scale": 0.7,
"max_scale": 2.0,
"size": 15.24,
"horiz_adv_x_default": null,
"horiz_adv_x_space": 51,
"units_per_em": 90,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 1,
"max_scale": 1.5,
"size": 20,
"horiz_adv_x_default": 49,
"horiz_adv_x_space": 20,
"units_per_em": 100,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 0.5,
"max_scale": 1.5,
"size": 90,
"horiz_adv_x_default": 280,
"horiz_adv_x_space": 20,
"units_per_em": 350,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "_",
"min_scale": 1.0,
"max_scale": 3.0,
"size": 8.5,
"horiz_adv_x_default": null,
"horiz_adv_x_space": 8,
"units_per_em": 100,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 0.8,
"max_scale": 1.4,
"size": 20,
"horiz_adv_x_default": 35,
"horiz_adv_x_space": 20,
"units_per_em": 75,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "<22>",
"min_scale": 0.25,
"max_scale": 0.55,
"size": 20,
"horiz_adv_x_default": 35,
"horiz_adv_x_space": 20,
"units_per_em": 75,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 1.3,
"size": 42.5,
"horiz_adv_x_default": 81,
"horiz_adv_x_space": 57,
"units_per_em": 138,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 1.3,
"size": 42.5,
"horiz_adv_x_default": 81,
"horiz_adv_x_space": 57,
"units_per_em": 138,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": " ",
"min_scale": 0.8,
"max_scale": 1.5,
"size": 16.4,
"horiz_adv_x_default": 28,
"horiz_adv_x_space": 20,
"units_per_em": 83,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": "<22>",
"min_scale": 0.7,
"max_scale": 3.0,
"size": 5.08,
"horiz_adv_x_default": null,
"horiz_adv_x_space": 17,
"units_per_em": 30,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "?",
"min_scale": 0.75,
"max_scale": 2.0,
"size": 150,
"horiz_adv_x_default": 468,
"horiz_adv_x_space": 350,
"units_per_em": 660,

Wyświetl plik

@ -8,6 +8,7 @@
"default_glyph": "?",
"min_scale": 0.70,
"max_scale":2.0,
"size": 90,
"horiz_adv_x_default": 234,
"horiz_adv_x_space": 150,
"units_per_em": 330,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": "?",
"min_scale": 1.0,
"max_scale": 5.0,
"size": 18.5,
"horiz_adv_x_default": 34,
"horiz_adv_x_space": 14,
"units_per_em": 100,

Wyświetl plik

@ -7,6 +7,7 @@
"default_glyph": "?",
"min_scale": 1.0,
"max_scale": 3.0,
"size": 18.5,
"horiz_adv_x_default": 63,
"horiz_adv_x_space": 22,
"units_per_em": 100,

Wyświetl plik

@ -9,10 +9,10 @@ import sys
from base64 import b64decode
import appdirs
import inkex
import wx
import wx.adv
import inkex
import wx.lib.agw.floatspin as fs
from ..elements import nodes_to_elements
from ..gui import PresetsPanel, SimulatorPreview, info_dialog
@ -30,13 +30,6 @@ class LetteringFrame(wx.Frame):
DEFAULT_FONT = "small_font"
def __init__(self, *args, **kwargs):
# This is necessary because of https://github.com/inkstitch/inkstitch/issues/1186
if sys.platform.startswith('win32'):
import locale
locale.setlocale(locale.LC_ALL, "C")
lc = wx.Locale()
lc.Init(wx.LANGUAGE_DEFAULT)
# begin wxGlade: MyFrame.__init__
self.group = kwargs.pop('group')
self.cancel_hook = kwargs.pop('on_cancel', None)
@ -52,12 +45,19 @@ class LetteringFrame(wx.Frame):
# font
self.font_selector_box = wx.StaticBox(self, wx.ID_ANY, label=_("Font"))
self.update_font_list()
self.font_chooser = wx.adv.BitmapComboBox(self, wx.ID_ANY, style=wx.CB_READONLY | wx.CB_SORT)
self.set_font_list()
self.font_chooser.Bind(wx.EVT_COMBOBOX, self.on_font_changed)
self.font_filter = fs.FloatSpin(self, min_val=0, max_val=None, increment=1, value="0")
self.font_filter.SetFormat("%f")
self.font_filter.SetDigits(2)
self.font_filter.Bind(fs.EVT_FLOATSPIN, self.on_filter_changed)
self.font_filter.SetToolTip(_("Font size filter (mm). 0 for all sizes."))
self.update_font_list()
self.set_font_list()
# font details
self.font_description = wx.StaticText(self, wx.ID_ANY)
self.Bind(wx.EVT_SIZE, self.resize)
@ -92,6 +92,12 @@ class LetteringFrame(wx.Frame):
self.load_settings()
self.apply_settings()
def InitLocale(self):
# This is necessary because of https://github.com/inkstitch/inkstitch/issues/1186
if sys.platform.startswith('win'):
import locale
locale.setlocale(locale.LC_ALL, "C")
def load_settings(self):
"""Load the settings saved into the SVG group element"""
@ -126,7 +132,10 @@ class LetteringFrame(wx.Frame):
"""Save the settings into the SVG group element."""
self.group.set(INKSTITCH_LETTERING, json.dumps(self.settings))
def update_font_list(self):
@property
@cache
def font_list(self):
fonts = []
font_paths = {
get_bundled_dir("fonts"),
os.path.expanduser("~/.inkstitch/fonts"),
@ -134,9 +143,6 @@ class LetteringFrame(wx.Frame):
get_custom_font_dir()
}
self.fonts = {}
self.fonts_by_id = {}
for font_path in font_paths:
try:
font_dirs = os.listdir(font_path)
@ -147,19 +153,27 @@ class LetteringFrame(wx.Frame):
font = Font(os.path.join(font_path, font_dir))
if font.marked_custom_font_name == "" or font.marked_custom_font_id == "":
continue
fonts.append(font)
return fonts
def update_font_list(self):
self.fonts = {}
self.fonts_by_id = {}
filter_size = self.font_filter.GetValue()
for font in self.font_list:
if filter_size != 0 and (filter_size < font.size * font.min_scale or filter_size > font.size * font.max_scale):
continue
self.fonts[font.marked_custom_font_name] = font
self.fonts_by_id[font.marked_custom_font_id] = font
if len(self.fonts) == 0:
info_dialog(self, _("Unable to find any fonts! Please try reinstalling Ink/Stitch."))
self.cancel()
def set_font_list(self):
self.font_chooser.Clear()
for font in self.fonts.values():
image = font.preview_image
if image is not None:
image = wx.Image(font.preview_image)
image = wx.Image(image)
"""
# I would like to do this but Windows requires all images to be the exact same size
# It might work with an updated wxpython version - so let's keep it here
@ -195,7 +209,6 @@ class LetteringFrame(wx.Frame):
self.on_font_changed()
@property
@cache
def default_font(self):
try:
return self.fonts_by_id[self.DEFAULT_FONT]
@ -209,7 +222,12 @@ class LetteringFrame(wx.Frame):
def on_font_changed(self, event=None):
font = self.fonts.get(self.font_chooser.GetValue(), self.default_font)
self.settings.font = font.marked_custom_font_id
filter_size = self.font_filter.GetValue()
self.scale_spinner.SetRange(int(font.min_scale * 100), int(font.max_scale * 100))
if filter_size != 0:
self.scale_spinner.SetValue(int(filter_size / font.size * 100))
self.settings['scale'] = self.scale_spinner.GetValue()
font_variants = []
try:
@ -245,6 +263,28 @@ class LetteringFrame(wx.Frame):
self.update_preview()
self.Layout()
def on_filter_changed(self, event=None):
self.update_font_list()
if not self.fonts:
# No fonts for filtered size
self.font_chooser.Clear()
self.filter_label.SetForegroundColour("red")
return
else:
self.filter_label.SetForegroundColour("black")
filter_size = self.font_filter.GetValue()
previous_font = self.font_chooser.GetValue()
self.set_font_list()
font = self.fonts.get(previous_font, self.default_font)
self.font_chooser.SetValue(font.name)
if font.name != previous_font:
self.on_font_changed()
elif filter_size != 0:
self.scale_spinner.SetValue(int(filter_size / font.size * 100))
self.settings['scale'] = self.scale_spinner.GetValue()
def resize(self, event=None):
description = self.font_description.GetLabel().replace("\n", " ")
self.font_description.SetLabel(description)
@ -255,6 +295,10 @@ class LetteringFrame(wx.Frame):
self.preview.update()
def update_lettering(self, raise_error=False):
# return if there is no font in the font list (possibly due to a font size filter)
if not self.font_chooser.GetValue():
return
del self.group[:]
if self.settings.scale == 100:
@ -344,7 +388,12 @@ class LetteringFrame(wx.Frame):
# font selection
font_selector_sizer = wx.StaticBoxSizer(self.font_selector_box, wx.VERTICAL)
font_selector_sizer.Add(self.font_chooser, 0, wx.EXPAND | wx.ALL, 10)
font_selector_box = wx.BoxSizer(wx.HORIZONTAL)
font_selector_box.Add(self.font_chooser, 4, wx.EXPAND | wx.TOP | wx.BOTTOM | wx.RIGHT, 10)
self.filter_label = wx.StaticText(self, wx.ID_ANY, "Filter")
font_selector_box.Add(self.filter_label, 0, wx.LEFT | wx.ALIGN_CENTRE_VERTICAL, 0)
font_selector_box.Add(self.font_filter, 1, wx.LEFT | wx.ALIGN_CENTRE_VERTICAL, 5)
font_selector_sizer.Add(font_selector_box, 0, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 10)
font_selector_sizer.Add(self.font_description, 1, wx.EXPAND | wx.ALL, 10)
outer_sizer.Add(font_selector_sizer, 0, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 10)

Wyświetl plik

@ -26,6 +26,7 @@ class LetteringGenerateJson(InkstitchExtension):
self.arg_parser.add_argument("-r", "--reversible", type=Boolean, default="true", dest="reversible")
self.arg_parser.add_argument("-u", "--letter-case", type=str, default="", dest="letter_case")
self.arg_parser.add_argument("-g", "--default-glyph", type=str, default="", dest="default_glyph")
self.arg_parser.add_argument("-z", "--size", type=float, default=15, dest="size")
self.arg_parser.add_argument("-i", "--min-scale", type=float, default=1.0, dest="min_scale")
self.arg_parser.add_argument("-a", "--max-scale", type=float, default=1.0, dest="max_scale")
self.arg_parser.add_argument("-c", "--use-custom-leading", type=Boolean, default="false", dest="use_custom_leading")
@ -71,6 +72,7 @@ class LetteringGenerateJson(InkstitchExtension):
'reversible': self.options.reversible,
'letter_case': self.options.letter_case,
'default_glyph': self.options.default_glyph,
'size': self.options.size,
'min_scale': round(self.options.min_scale, 1),
'max_scale': round(self.options.max_scale, 1),
'horiz_adv_x_default': letter_spacing,

Wyświetl plik

@ -411,7 +411,7 @@ class ParamsTab(ScrolledPanel):
class SettingsFrame(wx.Frame):
def __init__(self, *args, **kwargs):
# This is necessary because of https://github.com/inkstitch/inkstitch/issues/1186
if sys.platform.startswith('win32'):
if sys.platform.startswith('win'):
import locale
locale.setlocale(locale.LC_ALL, "C")
lc = wx.Locale()

Wyświetl plik

@ -117,6 +117,7 @@ class Font(object):
auto_satin = font_metadata('auto_satin', True)
min_scale = font_metadata('min_scale', 1.0)
max_scale = font_metadata('max_scale', 1.0)
size = font_metadata('size', 0)
# use values from SVG Font, example:
# <font horiz-adv-x="45" ... <glyph .... horiz-adv-x="49" glyph-name="A" /> ... <hkern ... k="3"g1="A" g2="B" /> .... />

Wyświetl plik

@ -40,6 +40,7 @@
</param>
</vbox>
<vbox indent="20">
<param name="size" type="float" precision="1" min="1" max="1000" gui-text="Size" indent="1">15</param>
<param name="min-scale" type="float" precision="1" min="0.1" max="1" gui-text="Min Scale" indent="1">1</param>
<param name="max-scale" type="float" precision="1" min="1" max="10" gui-text="Max Scale" indent="1">1</param>
</vbox>