diff options
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/lettering.py | 95 | ||||
| -rw-r--r-- | lib/extensions/lettering_generate_json.py | 2 | ||||
| -rw-r--r-- | lib/extensions/params.py | 2 |
3 files changed, 75 insertions, 24 deletions
diff --git a/lib/extensions/lettering.py b/lib/extensions/lettering.py index 658f2bc7..c870a764 100644 --- a/lib/extensions/lettering.py +++ b/lib/extensions/lettering.py @@ -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 - self.fonts[font.marked_custom_font_name] = font - self.fonts_by_id[font.marked_custom_font_id] = font + fonts.append(font) + return fonts - if len(self.fonts) == 0: - info_dialog(self, _("Unable to find any fonts! Please try reinstalling Ink/Stitch.")) - self.cancel() + 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 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) diff --git a/lib/extensions/lettering_generate_json.py b/lib/extensions/lettering_generate_json.py index 9296751c..85c918b2 100644 --- a/lib/extensions/lettering_generate_json.py +++ b/lib/extensions/lettering_generate_json.py @@ -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, diff --git a/lib/extensions/params.py b/lib/extensions/params.py index b60183e5..df62128f 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -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() |
