summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudine Peyrat <88194877+claudinepeyrat06@users.noreply.github.com>2025-04-26 08:52:31 +0200
committerGitHub <noreply@github.com>2025-04-26 08:52:31 +0200
commit7497a582840fa94415b56a8b45df593328d644ca (patch)
tree6f88b587088d8a02f49ac90961f86ba3f87fb426
parent4cfb02c370e2f09d59658f652c4b15bd41d46d6e (diff)
Claudine/fix font sample (#3684)
* twist monicha * Update lettering_font_sample.py * better use default value * and leave Monicha alone in this branch * ensure command and marker symbols --------- Co-authored-by: Kaalleen <reni@allenka.de>
-rw-r--r--fonts/monicha/→.svg4
-rw-r--r--lib/commands.py13
-rw-r--r--lib/gui/lettering_font_sample.py5
-rw-r--r--lib/lettering/font.py31
-rw-r--r--lib/marker.py15
5 files changed, 41 insertions, 27 deletions
diff --git a/fonts/monicha/→.svg b/fonts/monicha/→.svg
index 530740e0..6f4c87d1 100644
--- a/fonts/monicha/→.svg
+++ b/fonts/monicha/→.svg
@@ -6,7 +6,7 @@
width="100"
height="100"
viewBox="0 0 100 100"
- inkscape:version="1.3.2 (091e20e, 2023-11-25)"
+ inkscape:version="1.4-rc1 (61ec3f24, 2024-09-26)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
@@ -29,7 +29,7 @@
id="namedview461"
showgrid="true"
inkscape:zoom="11.955185"
- inkscape:cx="23.211685"
+ inkscape:cx="23.169863"
inkscape:cy="11.041234"
inkscape:window-x="0"
inkscape:window-y="25"
diff --git a/lib/commands.py b/lib/commands.py
index 24c045ee..37081f11 100644
--- a/lib/commands.py
+++ b/lib/commands.py
@@ -344,6 +344,19 @@ def ensure_symbol(svg, command) -> None:
defs.append(symbol)
+def ensure_command_symbols(group):
+ """Make sure all commands used in a svg group exist in the <svg:defs> tag"""
+ # collect commands
+ commands = set()
+ for element in group.iterdescendants(SVG_USE_TAG):
+ xlink = element.get(XLINK_HREF, ' ')
+ if xlink.startswith('#inkstitch_'):
+ commands.add(xlink[11:])
+ # make sure all necessary command symbols are in the document
+ for command in commands:
+ ensure_symbol(group.getroottree().getroot(), command)
+
+
def add_group(document, node, command):
parent = node.getparent()
description = _(get_command_description(command))
diff --git a/lib/gui/lettering_font_sample.py b/lib/gui/lettering_font_sample.py
index 862e3f7c..e19544dc 100644
--- a/lib/gui/lettering_font_sample.py
+++ b/lib/gui/lettering_font_sample.py
@@ -9,8 +9,10 @@ import wx
import wx.adv
from inkex import Group, errormsg
+from ..commands import ensure_command_symbols
from ..i18n import _
from ..lettering import get_font_list
+from ..marker import ensure_marker_symbols
from ..utils.settings import global_settings
@@ -268,6 +270,9 @@ class FontSampleFrame(wx.Frame):
if self.sortable():
self.font.do_color_sort(self.layer, 1)
+ ensure_command_symbols(group)
+ ensure_marker_symbols(group)
+
def _render_glyph(self, group, glyph, position, character, last_character):
node = deepcopy(glyph.node)
if last_character is not None:
diff --git a/lib/lettering/font.py b/lib/lettering/font.py
index cc81cc9d..50fb804f 100644
--- a/lib/lettering/font.py
+++ b/lib/lettering/font.py
@@ -11,12 +11,13 @@ from random import randint
import inkex
-from ..commands import add_commands, ensure_symbol
+from ..commands import add_commands, ensure_command_symbols
from ..elements import SatinColumn, Stroke, nodes_to_elements
from ..exceptions import InkstitchException
from ..extensions.lettering_custom_font_dir import get_custom_font_dir
from ..i18n import _, get_languages
-from ..marker import MARKER, ensure_marker, has_marker, is_grouped_with_marker
+from ..marker import (MARKER, ensure_marker_symbols, has_marker,
+ is_grouped_with_marker)
from ..stitches.auto_satin import auto_satin
from ..svg.clip import get_clips
from ..svg.tags import (CONNECTION_END, CONNECTION_START, EMBROIDERABLE_TAGS,
@@ -282,8 +283,8 @@ class Font(object):
# add trims
self._add_trims(destination_group, text, trim_option, use_trim_symbols, back_and_forth, color_sort)
# make sure necessary marker and command symbols are in the defs section
- self._ensure_command_symbols(destination_group)
- self._ensure_marker_symbols(destination_group)
+ ensure_command_symbols(destination_group)
+ ensure_marker_symbols(destination_group)
if color_sort != 0 and self.sortable:
self.do_color_sort(destination_group, color_sort)
@@ -443,7 +444,7 @@ class Font(object):
return node
- def _update_commands(self, node, glyph, id_extension):
+ def _update_commands(self, node, glyph, id_extension=""):
for element, connectors in glyph.commands.items():
# update element
el = node.find(".//*[@id='%s']" % element)
@@ -537,26 +538,6 @@ class Font(object):
else:
add_commands(element, ['trim'])
- def _ensure_command_symbols(self, group):
- # collect commands
- commands = set()
- for element in group.iterdescendants(SVG_USE_TAG):
- xlink = element.get(XLINK_HREF, ' ')
- if xlink.startswith('#inkstitch_'):
- commands.add(xlink[11:])
- # make sure all necessary command symbols are in the document
- for command in commands:
- ensure_symbol(group.getroottree().getroot(), command)
-
- def _ensure_marker_symbols(self, group):
- for marker in MARKER:
- xpath = ".//*[contains(@style, 'marker-start:url(#inkstitch-%s-marker')]" % marker
- marked_elements = group.xpath(xpath, namespaces=inkex.NSS)
- if marked_elements:
- ensure_marker(group.getroottree().getroot(), marker)
- for element in marked_elements:
- element.style['marker-start'] = "url(#inkstitch-%s-marker)" % marker
-
def _apply_auto_satin(self, group):
"""Apply Auto-Satin to an SVG XML node tree with an svg:g at its root.
diff --git a/lib/marker.py b/lib/marker.py
index 9765fbfb..a2b0965a 100644
--- a/lib/marker.py
+++ b/lib/marker.py
@@ -15,7 +15,10 @@ from .utils import cache, get_bundled_dir
MARKER = ['anchor-line', 'pattern', 'guide-line']
+@cache
def ensure_marker(svg, marker):
+ """Make sure a marker symbol is defined in the svg"""
+
marker_path = ".//*[@id='inkstitch-%s-marker']" % marker
if svg.defs.find(marker_path) is None:
marker = deepcopy(_marker_svg().defs.find(marker_path))
@@ -23,6 +26,18 @@ def ensure_marker(svg, marker):
svg.defs.append(marker)
+def ensure_marker_symbols(group):
+ """Make sure all marker symbols of an svg group is defined in the svg"""
+
+ for marker in MARKER:
+ xpath = ".//*[contains(@style, 'marker-start:url(#inkstitch-%s-marker')]" % marker
+ marked_elements = group.xpath(xpath, namespaces=NSS)
+ if marked_elements:
+ ensure_marker(group.getroottree().getroot(), marker)
+ for element in marked_elements:
+ element.style['marker-start'] = "url(#inkstitch-%s-marker)" % marker
+
+
@cache
def _marker_svg():
marker_path = path.join(get_bundled_dir("symbols"), "marker.svg")