mark custom fonts (#1159)

pull/1288/head
Kaalleen 2021-07-26 18:54:38 +02:00 zatwierdzone przez GitHub
rodzic 2f35a4a192
commit 37c76aafba
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 39 dodań i 17 usunięć

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 19 KiB

Wyświetl plik

@ -13,8 +13,6 @@ import inkex
import wx
import wx.adv
from .commands import CommandsExtension
from .lettering_custom_font_dir import get_custom_font_dir
from ..elements import nodes_to_elements
from ..gui import PresetsPanel, SimulatorPreview, info_dialog
from ..i18n import _
@ -22,7 +20,9 @@ from ..lettering import Font, FontError
from ..svg import get_correction_transform
from ..svg.tags import (INKSCAPE_LABEL, INKSTITCH_LETTERING, SVG_GROUP_TAG,
SVG_PATH_TAG)
from ..utils import DotDict, cache, get_bundled_dir
from ..utils import DotDict, cache, get_bundled_dir, get_resource_dir
from .commands import CommandsExtension
from .lettering_custom_font_dir import get_custom_font_dir
class LetteringFrame(wx.Frame):
@ -41,6 +41,9 @@ class LetteringFrame(wx.Frame):
_("Ink/Stitch Lettering")
)
icon = wx.Icon(os.path.join(get_resource_dir("icons"), "inkstitch256x256.png"))
self.SetIcon(icon)
self.preview = SimulatorPreview(self, target_duration=1)
self.presets_panel = PresetsPanel(self)
@ -139,10 +142,10 @@ class LetteringFrame(wx.Frame):
for font_dir in font_dirs:
font = Font(os.path.join(font_path, font_dir))
if font.name == "" or font.id == "":
if font.marked_custom_font_name == "" or font.marked_custom_font_id == "":
continue
self.fonts[font.name] = font
self.fonts_by_id[font.id] = font
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."))
@ -151,6 +154,7 @@ class LetteringFrame(wx.Frame):
def set_font_list(self):
for font in self.fonts.values():
image = font.preview_image
if image is not None:
image = wx.Image(font.preview_image)
"""
@ -166,16 +170,10 @@ class LetteringFrame(wx.Frame):
"""
# Windows requires all images to have the exact same size
image.Rescale(300, 20, quality=wx.IMAGE_QUALITY_HIGH)
self.font_chooser.Append(font.name, wx.Bitmap(image))
self.font_chooser.Append(font.marked_custom_font_name, wx.Bitmap(image))
else:
self.font_chooser.Append(font.name)
def get_font_names(self):
font_names = [font.name for font in self.fonts.values()]
font_names.sort()
return font_names
def get_font_descriptions(self):
return {font.name: font.description for font in self.fonts.values()}
@ -186,9 +184,11 @@ class LetteringFrame(wx.Frame):
'''A default font will be substituted.'''
info_dialog(self, _(message) % font_id)
try:
self.font_chooser.SetValue(self.fonts_by_id[font_id].name)
font = self.fonts_by_id[font_id].marked_custom_font_name
except KeyError:
self.font_chooser.SetValue(self.default_font.name)
font = self.default_font.name
self.font_chooser.SetValue(font)
self.on_font_changed()
@property
@ -205,7 +205,7 @@ 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.id
self.settings.font = font.marked_custom_font_id
self.scale_spinner.SetRange(int(font.min_scale * 100), int(font.max_scale * 100))
font_variants = []

Wyświetl plik

@ -341,6 +341,10 @@ class SettingsFrame(wx.Frame):
wx.Frame.__init__(self, None, wx.ID_ANY,
_("Embroidery Params")
)
icon = wx.Icon(os.path.join(get_resource_dir("icons"), "inkstitch256x256.png"))
self.SetIcon(icon)
self.notebook = wx.Notebook(self, wx.ID_ANY)
self.tabs = self.tabs_factory(self.notebook)

Wyświetl plik

@ -9,13 +9,14 @@ from copy import deepcopy
import inkex
from .font_variant import FontVariant
from ..elements import nodes_to_elements
from ..exceptions import InkstitchException
from ..extensions.lettering_custom_font_dir import get_custom_font_dir
from ..i18n import _, get_languages
from ..stitches.auto_satin import auto_satin
from ..svg.tags import INKSCAPE_LABEL, SVG_PATH_TAG
from ..utils import Point
from .font_variant import FontVariant
class FontError(InkstitchException):
@ -157,6 +158,23 @@ class Font(object):
raise FontError(_("The font '%s' has no variants.") % self.name)
return font_variants
@property
def marked_custom_font_id(self):
if not self.is_custom_font():
return self.id
else:
return self.id + '*'
@property
def marked_custom_font_name(self):
if not self.is_custom_font():
return self.name
else:
return self.name + '*'
def is_custom_font(self):
return get_custom_font_dir() in self.path
def render_text(self, text, destination_group, variant=None, back_and_forth=True, trim=False):
"""Render text into an SVG group element."""
self._load_variants()