From a0a3fab4c9578027ae9af4aa2eec0b3a363df20c Mon Sep 17 00:00:00 2001 From: Claudine Peyrat <88194877+claudinepeyrat06@users.noreply.github.com> Date: Wed, 25 Jun 2025 10:30:24 +0200 Subject: switch from NFKC to NFC normalization form in the lettering tool (#3828) * switch from NFKC to NFC * Additional normalization. --------- Co-authored-by: CapellanCitizen <> --- lib/gui/lettering/main_panel.py | 7 ++++--- lib/lettering/font.py | 4 ++++ lib/lettering/font_variant.py | 4 ++-- lib/lettering/glyph.py | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/gui/lettering/main_panel.py b/lib/gui/lettering/main_panel.py index 64312b5a..f0532560 100644 --- a/lib/gui/lettering/main_panel.py +++ b/lib/gui/lettering/main_panel.py @@ -5,6 +5,7 @@ import json from base64 import b64decode +import unicodedata import inkex import wx @@ -126,11 +127,11 @@ class LetteringPanel(wx.Panel): filter_glyph = self.options_panel.font_glyph_filter.GetValue() filter_category = self.options_panel.font_category_filter.GetSelection() - 1 - # glyph filter string without spaces - glyphs = [*self.options_panel.text_editor.GetValue().replace(" ", "").replace("\n", "")] + # 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", ""))) for font in self.font_list: - if filter_glyph and glyphs and not set(glyphs).issubset(font.available_glyphs): + if filter_glyph and glyphs and not glyphs.issubset(font.available_glyphs): continue if filter_category != -1: diff --git a/lib/lettering/font.py b/lib/lettering/font.py index d1ed6154..5ae6743a 100644 --- a/lib/lettering/font.py +++ b/lib/lettering/font.py @@ -8,6 +8,7 @@ import os from collections import defaultdict from copy import deepcopy from random import randint +import unicodedata import inkex @@ -217,6 +218,9 @@ class Font(object): """Render text into an SVG group element.""" self._load_variants() + # Normalize the text in the same way that glyph names are normalized (NFC) + text = unicodedata.normalize('NFC', text) + if variant is None: variant = self.default_variant diff --git a/lib/lettering/font_variant.py b/lib/lettering/font_variant.py index 4862b00b..80d9d3e6 100644 --- a/lib/lettering/font_variant.py +++ b/lib/lettering/font_variant.py @@ -74,7 +74,7 @@ class FontVariant(object): for layer in glyph_layers: self._clean_group(layer) layer.attrib[INKSCAPE_LABEL] = layer.attrib[INKSCAPE_LABEL].replace("GlyphLayer-", "", 1) - glyph_name = normalize('NFKC', layer.attrib[INKSCAPE_LABEL]) + glyph_name = normalize('NFC', layer.attrib[INKSCAPE_LABEL]) try: self.glyphs[glyph_name] = Glyph(layer) except (AttributeError, ValueError): @@ -144,7 +144,7 @@ class FontVariant(object): # binding glyph only have two shapes, isol and fina non_binding_char = ['ا', 'أ', 'ﺇ', 'آ', 'ٱ', 'د', 'ذ', 'ر', 'ز', 'و', 'ؤ'] - normalized_non_binding_char = [normalize('NFKC', letter) for letter in non_binding_char] + normalized_non_binding_char = [normalize('NFC', letter) for letter in non_binding_char] return not (character in normalized_non_binding_char) def is_mark(self, character): diff --git a/lib/lettering/glyph.py b/lib/lettering/glyph.py index fd1e1985..98f69ecb 100644 --- a/lib/lettering/glyph.py +++ b/lib/lettering/glyph.py @@ -39,7 +39,7 @@ class Glyph(object): self.name = group.label if len(self.name) > 11: - self.name = normalize('NFKC', self.name[11:]) + self.name = normalize('NFC', self.name[11:]) self._process_baseline(group.getroottree().getroot()) self.clips = self._process_clips(group) self.node = self._process_group(group) -- cgit v1.2.3