diff options
| author | Claudine Peyrat <88194877+claudinepeyrat06@users.noreply.github.com> | 2025-07-06 14:00:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-06 14:00:28 +0200 |
| commit | 3fbdf3b746c2b9345d44599599b8f0ddd891577e (patch) | |
| tree | a6f259dd36e75dbf1b56854b772e2ef9c8a99438 /lib | |
| parent | a2a7d7d149491478426ba1911ad5767bddf8e4eb (diff) | |
Claudine/fix normalization and house cleaning (#3843)
* remove normalization in glyph filter
remove glyph normalization gui/lettering/main_panel, as it breaks the glyph filtering
remove some spelling mistake in the comments, correct some comment
if a glyph from the svg font file is a non chasing mark (like combining accent, or cedilla) the inkscape label of the corresponding glyph group created by lettering_font_sample was empty or unreadable, make it visible . Same in the line label.
and although it is not related
correct one glyph in malika font
* correct warning in lettering_font_sample
do the warnings correctly when there is somethng wrong with the glyph list in the font.json gile
* Update lettering_font_sample.py
fix a typo
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/extensions/lettering_edit_json.py | 2 | ||||
| -rw-r--r-- | lib/gui/lettering/main_panel.py | 9 | ||||
| -rw-r--r-- | lib/gui/lettering_font_sample.py | 63 | ||||
| -rw-r--r-- | lib/lettering/font.py | 5 | ||||
| -rw-r--r-- | lib/lettering/font_variant.py | 7 |
5 files changed, 52 insertions, 34 deletions
diff --git a/lib/extensions/lettering_edit_json.py b/lib/extensions/lettering_edit_json.py index b86c4fcb..3c5aa3f4 100644 --- a/lib/extensions/lettering_edit_json.py +++ b/lib/extensions/lettering_edit_json.py @@ -16,7 +16,7 @@ from .base import InkstitchExtension class LetteringEditJson(InkstitchExtension): ''' - This extension helps font creators to generate an output of every glyph from a selected font + This extension helps font creators modify the JSON file of a lettering font. ''' def effect(self): layer = Layer() diff --git a/lib/gui/lettering/main_panel.py b/lib/gui/lettering/main_panel.py index f0532560..fc6d16ad 100644 --- a/lib/gui/lettering/main_panel.py +++ b/lib/gui/lettering/main_panel.py @@ -5,7 +5,6 @@ import json from base64 import b64decode -import unicodedata import inkex import wx @@ -123,12 +122,16 @@ class LetteringPanel(wx.Panel): self.fonts_by_id = {} # font size filter value + filter_size = self.options_panel.font_size_filter.GetValue() filter_glyph = self.options_panel.font_glyph_filter.GetValue() filter_category = self.options_panel.font_category_filter.GetSelection() - 1 # Set of all glyphs in input string (except whitespace characters), normalized in the same way that we normalize font glyphs - glyphs = set(*unicodedata.normalize("NFC", self.options_panel.text_editor.GetValue().replace(r"\s", ""))) + # do not normalize the glyphs yet, available_glyphs are not normalized in the font json file + # glyphs = set(l for l in unicodedata.normalize("NFC", self.options_panel.text_editor.GetValue().replace(r"\s", ""))) + + glyphs = set(letter for letter in self.options_panel.text_editor.GetValue().replace(r"\s", "")) for font in self.font_list: if filter_glyph and glyphs and not glyphs.issubset(font.available_glyphs): @@ -319,7 +322,7 @@ class LetteringPanel(wx.Panel): else: pass - # the text scaling group label is dependend on the user language, so it would break in international file exchange if we used it + # the text scaling group label is dependent on the user language, so it would break in international file exchange if we used it # scaling (correction transform) on the parent group is already applied, so let's use that for recognition if destination_group.get('transform', None) is None: destination_group.attrib['transform'] = 'scale(%s)' % (self.settings.scale / 100.0) diff --git a/lib/gui/lettering_font_sample.py b/lib/gui/lettering_font_sample.py index e19544dc..9f42a755 100644 --- a/lib/gui/lettering_font_sample.py +++ b/lib/gui/lettering_font_sample.py @@ -8,6 +8,7 @@ from copy import deepcopy import wx import wx.adv from inkex import Group, errormsg +import unicodedata from ..commands import ensure_command_symbols from ..i18n import _ @@ -178,29 +179,14 @@ class FontSampleFrame(wx.Frame): text = '' width = 0 last_glyph = None - printed_warning = False - update_glyphlist_warning = _( - "The glyphlist for this font seems to be outdated.\n\n" - "Please update the glyph list for {font_name}:\n" - "* Open Extensions > Ink/Stitch > Font Management > Edit JSON\n" - "* Select this font and apply." - ).format(font_name=self.font.marked_custom_font_name) - - self.duplicate_warning() - - # font variant glyph list length falls short if a single quote sign is available - # let's add it in the length comparison - if len(set(self.font.available_glyphs)) != len(self.font_variant.glyphs): - errormsg(update_glyphlist_warning) - printed_warning = True + outdated = False for glyph in self.font.available_glyphs: glyph_obj = self.font_variant[glyph] if glyph_obj is None: - if not printed_warning: - errormsg(update_glyphlist_warning) - printed_warning = True + outdated = True continue + if last_glyph is not None: width_to_add = (glyph_obj.min_x - self.font.kerning_pairs.get(f'{last_glyph} {glyph}', 0)) * scale width += width_to_add @@ -219,8 +205,8 @@ class FontSampleFrame(wx.Frame): text += glyph width += width_to_add + self.out_dated_warning(outdated) self._render_text(text) - self.GetTopLevelParent().Close() def sortable(self): @@ -229,20 +215,40 @@ class FontSampleFrame(wx.Frame): color_sort = False return color_sort - def duplicate_warning(self): - # warn about duplicated glyphs + def out_dated_warning(self, outdated=False): + # called with outdated == True when some glyphs present in the font.json glyph list are not present in the svg font file + + update_glyphlist_warning = _( + "The glyphlist for this font seems to be outdated.\n\n" + "Please update the glyph list for {font_name}:\n" + "* Open Extensions > Ink/Stitch > Font Management > Edit JSON\n" + "* Select this font and apply." + ).format(font_name=self.font.marked_custom_font_name) + + # warning in case of duplicates in the glyph list of the font.json file if len(set(self.font.available_glyphs)) != len(self.font.available_glyphs): - duplicated_glyphs = " ".join( - [glyph for glyph in set(self.font.available_glyphs) if self.font.available_glyphs.count(glyph) > 1] - ) - errormsg(_("Found duplicated glyphs in font file: {duplicated_glyphs}").format(duplicated_glyphs=duplicated_glyphs)) + outdated = True + + # this will cause a warning if some glyphs of the svg font are not present in the font.json glyph list + if len(set(self.font.available_glyphs)) != len(self.font_variant.glyphs): + outdated = True + + if outdated: + errormsg(update_glyphlist_warning) def _render_text(self, text): lines = text.splitlines() position = {'x': 0, 'y': 0} for line in lines: group = Group() - group.label = line + label = "" + # make the label of the group line clearly show the non spacing marks + for character in line: + if unicodedata.category(character) != 'Mn': + label += character + else: + label += ' ' + character + group.label = label group.set("inkstitch:letter-group", "line") glyphs = [] skip = [] @@ -297,7 +303,12 @@ class FontSampleFrame(wx.Frame): # because this is not unique it will be overwritten by inkscape when inserted into the document node.set("id", "glyph") node.set("inkstitch:letter-group", "glyph") + # force inkscape to show a label when the glyph is only a non spacing mark + if len(node.label) == 1 and unicodedata.category(node.label) == 'Mn': + node.label = ' ' + node.label + group.add(node) + return position def cancel(self, event): diff --git a/lib/lettering/font.py b/lib/lettering/font.py index 5ae6743a..1d9f8b40 100644 --- a/lib/lettering/font.py +++ b/lib/lettering/font.py @@ -452,7 +452,10 @@ class Font(object): # because this is not unique it will be overwritten by inkscape when inserted into the document node.set("id", "glyph") node.set("inkstitch:letter-group", "glyph") - + # force inkscape to show a label when the glyph is only a non-spacing mark + if len(node.label) == 1 and unicodedata.category(node.label) == 'Mn': + # force inkscape to show a label when the glyph is only a non-spacing mark + node.label = ' ' + node.label return node def _update_commands(self, node, glyph, id_extension=""): diff --git a/lib/lettering/font_variant.py b/lib/lettering/font_variant.py index 80d9d3e6..0e4836e8 100644 --- a/lib/lettering/font_variant.py +++ b/lib/lettering/font_variant.py @@ -198,7 +198,7 @@ class FontVariant(object): shape = 'fina' else: shape = 'isol' - # in the middle of the actual word, the shape of a glyph is medi if previous glyph is bendinng, init otherwise + # in the middle of the actual word, the shape of a glyph is medi if previous glyph is binding, init otherwise elif previous_is_binding: shape = 'medi' else: @@ -207,9 +207,10 @@ class FontVariant(object): return shape def get_next_glyph(self, word, i, previous_is_binding): - # search for the glyph of word that starts at i,taking into acount the previous glyph binding status + # word[:i] has been processed, this function returns the glyph starting at word[i] + # taking into acount the previous glyph binding status - # find all the glyphs in tthe font that start with first letter of the glyph + # find all the glyphs in the font that start with first letter of the glyph glyph_selection = self.glyphs_start_with(word[i]) # find the longest glyph that match |
