From 2f35a4a192eb6aa3b68b715da6c1ba984084e0e5 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Sun, 25 Jul 2021 07:24:34 +0200 Subject: Fix Style Issues (#1154) Co-authored-by: Lex Neva --- lib/lettering/font.py | 11 +++++------ lib/lettering/font_variant.py | 16 +++++----------- lib/lettering/glyph.py | 5 +---- 3 files changed, 11 insertions(+), 21 deletions(-) (limited to 'lib/lettering') diff --git a/lib/lettering/font.py b/lib/lettering/font.py index d241bf05..cbd8f257 100644 --- a/lib/lettering/font.py +++ b/lib/lettering/font.py @@ -7,16 +7,15 @@ import json import os from copy import deepcopy -from inkex import styles -from lxml import etree +import inkex +from .font_variant import FontVariant from ..elements import nodes_to_elements from ..exceptions import InkstitchException from ..i18n import _, get_languages from ..stitches.auto_satin import auto_satin -from ..svg.tags import INKSCAPE_LABEL, SVG_GROUP_TAG, SVG_PATH_TAG +from ..svg.tags import INKSCAPE_LABEL, SVG_PATH_TAG from ..utils import Point -from .font_variant import FontVariant class FontError(InkstitchException): @@ -190,7 +189,7 @@ class Font(object): for element in destination_group.iterdescendants(SVG_PATH_TAG): dash_array = "" stroke_width = "" - style = styles.Style(element.get('style')) + style = inkex.styles.Style(element.get('style')) if style.get('fill') == 'none': stroke_width = ";stroke-width:1px" @@ -224,7 +223,7 @@ class Font(object): An svg:g element containing the rendered text. """ - group = etree.Element(SVG_GROUP_TAG, { + group = inkex.Group(attrib={ INKSCAPE_LABEL: line }) diff --git a/lib/lettering/font_variant.py b/lib/lettering/font_variant.py index b1e38368..d9d8ed44 100644 --- a/lib/lettering/font_variant.py +++ b/lib/lettering/font_variant.py @@ -6,7 +6,6 @@ import os import inkex -from lxml import etree from ..svg.tags import INKSCAPE_GROUPMODE, INKSCAPE_LABEL from .glyph import Glyph @@ -61,8 +60,7 @@ class FontVariant(object): def _load_glyphs(self): svg_path = os.path.join(self.path, "%s.svg" % self.variant) - with open(svg_path, encoding="utf-8") as svg_file: - svg = etree.parse(svg_file) + svg = inkex.load_svg(svg_path) glyph_layers = svg.xpath(".//svg:g[starts-with(@inkscape:label, 'GlyphLayer-')]", namespaces=inkex.NSS) for layer in glyph_layers: @@ -76,14 +74,10 @@ class FontVariant(object): # glyph. del group.attrib[INKSCAPE_GROUPMODE] - style_text = group.get('style') - - if style_text: - # The layer may be marked invisible, so we'll clear the 'display' - # style. - style = dict(inkex.Style.parse_str(group.get('style'))) - style.pop('display') - group.set('style', str(inkex.Style(style))) + # The layer may be marked invisible, so we'll clear the 'display' + # style and presentation attribute. + group.style.pop('display', None) + group.attrib.pop('display', None) def __getitem__(self, character): if character in self.glyphs: diff --git a/lib/lettering/glyph.py b/lib/lettering/glyph.py index 3bedd7ed..047c12cf 100644 --- a/lib/lettering/glyph.py +++ b/lib/lettering/glyph.py @@ -8,7 +8,6 @@ from copy import copy from inkex import paths, transforms from ..svg import get_guides -from ..svg.path import get_correction_transform from ..svg.tags import SVG_GROUP_TAG, SVG_PATH_TAG @@ -53,9 +52,7 @@ class Glyph(object): node_copy = copy(node) if "d" in node.attrib: - transform = -transforms.Transform(get_correction_transform(node, True)) - path = paths.Path(node.get("d")).transform(transform).to_absolute() - node_copy.set("d", str(path)) + node_copy.path = node.path.transform(node.composed_transform()).to_absolute() # Delete transforms from paths and groups, since we applied # them to the paths already. -- cgit v1.3.1 From 37c76aafba1f1f48cdcc69f3410abd719f5076f1 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Mon, 26 Jul 2021 18:54:38 +0200 Subject: mark custom fonts (#1159) --- icons/inkstitch256x256.png | Bin 0 -> 19440 bytes lib/extensions/lettering.py | 32 ++++++++++++++++---------------- lib/extensions/params.py | 4 ++++ lib/lettering/font.py | 20 +++++++++++++++++++- 4 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 icons/inkstitch256x256.png (limited to 'lib/lettering') diff --git a/icons/inkstitch256x256.png b/icons/inkstitch256x256.png new file mode 100644 index 00000000..f3e5f0e7 Binary files /dev/null and b/icons/inkstitch256x256.png differ diff --git a/lib/extensions/lettering.py b/lib/extensions/lettering.py index 75a18b24..875dea03 100644 --- a/lib/extensions/lettering.py +++ b/lib/extensions/lettering.py @@ -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 = [] diff --git a/lib/extensions/params.py b/lib/extensions/params.py index 40494ec7..82cc9be9 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -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) diff --git a/lib/lettering/font.py b/lib/lettering/font.py index cbd8f257..81044853 100644 --- a/lib/lettering/font.py +++ b/lib/lettering/font.py @@ -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() -- cgit v1.3.1 From e6fad808e9459ed6211c5ee04f3f1a00b786fa7a Mon Sep 17 00:00:00 2001 From: luzpaz Date: Thu, 29 Jul 2021 14:52:44 -0400 Subject: Fix typos (#1291) --- images/examples/Bfly FSL.svg | 2 +- lib/elements/element.py | 2 +- lib/elements/satin_column.py | 2 +- lib/elements/stroke.py | 2 +- lib/lettering/font.py | 2 +- lib/threads/catalog.py | 2 +- lib/utils/version.py | 2 +- print/resources/style.css | 4 ++-- 8 files changed, 9 insertions(+), 9 deletions(-) (limited to 'lib/lettering') diff --git a/images/examples/Bfly FSL.svg b/images/examples/Bfly FSL.svg index 9e528f1e..8acc49e1 100644 --- a/images/examples/Bfly FSL.svg +++ b/images/examples/Bfly FSL.svg @@ -214,7 +214,7 @@ x="0" y="244.13913" style="stroke-width:0.26458332px" - id="tspan4781">have to experiement to find out what ishave to experiment to find out what is ... .... /> # Example font.json : "horiz_adv_x": {"A":49}, diff --git a/lib/threads/catalog.py b/lib/threads/catalog.py index c3ccb0c3..c12ca1fe 100644 --- a/lib/threads/catalog.py +++ b/lib/threads/catalog.py @@ -75,7 +75,7 @@ class _ThreadCatalog(Sequence): Scans the catalog of color palettes and chooses one that seems most likely to be the one that the user used. A palette will only be - chosen if more tha 80% of the thread colors in the stitch plan are + chosen if more than 80% of the thread colors in the stitch plan are exact matches for threads in the palette. """ if not self.palettes: diff --git a/lib/utils/version.py b/lib/utils/version.py index 57ef11f0..2186ca23 100644 --- a/lib/utils/version.py +++ b/lib/utils/version.py @@ -18,5 +18,5 @@ def get_inkstitch_version(): with open(version, 'r') as v: inkstitch_version = _("Ink/Stitch Version: %s") % v.readline() else: - inkstitch_version = _("Ink/Stitch Version: unkown") + inkstitch_version = _("Ink/Stitch Version: unknown") return inkstitch_version diff --git a/print/resources/style.css b/print/resources/style.css index ca3d393f..d4a05e52 100644 --- a/print/resources/style.css +++ b/print/resources/style.css @@ -1089,13 +1089,13 @@ body { width: calc(100% / 10); } - /* fourty items */ + /* forty items */ .color-swatch:first-child:nth-last-child(n+40), .color-swatch:first-child:nth-last-child(n+40) ~ .color-swatch { width: calc(100% / 12); } - /* fourty-nine items */ + /* forty-nine items */ .color-swatch:first-child:nth-last-child(n+49), .color-swatch:first-child:nth-last-child(n+40) ~ .color-swatch { height: calc(100% / 5); -- cgit v1.3.1