From 71e7ae0b4500165e41d415fc1929299d06b6871e Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Sun, 25 Aug 2024 17:38:17 +0200 Subject: [PATCH] font-patcher: Rename glyphs to our ID / Class name [why] The glyphnames in the font files are sometimes off. We take them from the symbol source/font and ofter they are empty or even plain wrong (esp if we move to other codepoints). [how] We have the list of all glyphnames that is generated by collecting all data from the i_*.sh files. When patching we take this information now and use it if appropriate. Make sure the glyphname.json file is included in our zip patcher release and also in the Docker image. It will run as before if the file can not be found or is invalid etc. Suggested-by: Ulices Signed-off-by: Fini Jastrow --- .dockerignore | 1 + bin/scripts/archive-font-patcher.sh | 1 + font-patcher | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 2d68d42c77..0283a0b241 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,7 @@ ** !src/glyphs !font-patcher +!glyphnames.json !bin/scripts/name_parser/Fontname*.py !bin/scripts/docker-entrypoint.sh !.codeclimate.yml diff --git a/bin/scripts/archive-font-patcher.sh b/bin/scripts/archive-font-patcher.sh index 4cef5a902a..a86a1df2bd 100755 --- a/bin/scripts/archive-font-patcher.sh +++ b/bin/scripts/archive-font-patcher.sh @@ -29,6 +29,7 @@ find "${outputdir:?}" -name "FontPatcher.zip" -type f -delete cd -- "$scripts_root_dir/../../" || exit 1 find "src/glyphs" | zip -9 "$outputdir/FontPatcher" -@ find "bin/scripts/name_parser" -name "Fontname*.py" | zip -9 "$outputdir/FontPatcher" -@ +find "glyphnames.json" | zip -9 "$outputdir/FontPatcher" -@ find "font-patcher" | zip -9 "$outputdir/FontPatcher" -@ # add mini readme file diff --git a/font-patcher b/font-patcher index ac72ece759..fe8b91ea6c 100755 --- a/font-patcher +++ b/font-patcher @@ -6,7 +6,7 @@ from __future__ import absolute_import, print_function, unicode_literals # Change the script version when you edit this script: -script_version = "4.14.4" +script_version = "4.15.0" version = "3.2.1" projectName = "Nerd Fonts" @@ -318,6 +318,16 @@ def create_filename(fonts): sfnt_psubfam = '-' + sfnt_psubfam return (sfnt_pfam + sfnt_psubfam).replace(' ', '') +def fetch_glyphnames(): + """ Read the glyphname database and put it into a dictionary """ + try: + glyphnamefile = os.path.abspath(os.path.dirname(sys.argv[0])) + '/glyphnames.json' + with open(glyphnamefile, 'r') as f: + namelist = json.load(f) + return { int(v['code'], 16): k for k, v in namelist.items() if 'code' in v } + except Exception as error: + logger.warning("Can not read glyphnames file (%s)", repr(error)) + return {} class font_patcher: def __init__(self, args, conf): @@ -333,6 +343,7 @@ class font_patcher: self.onlybitmaps = 0 self.essential = set() self.xavgwidth = [] # list of ints + self.glyphnames = fetch_glyphnames() def patch(self, font): self.sourceFont = font @@ -1481,7 +1492,8 @@ class font_patcher: # Paste it self.sourceFont.selection.select(currentSourceFontGlyph) self.sourceFont.paste() - self.sourceFont[currentSourceFontGlyph].glyphname = sym_glyph.glyphname + self.sourceFont[currentSourceFontGlyph].glyphname = \ + self.glyphnames.get(currentSourceFontGlyph, sym_glyph.glyphname) if setName != 'Custom' else sym_glyph.glyphname self.sourceFont[currentSourceFontGlyph].manualHints = True # No autohints for symbols # Prepare symbol glyph dimensions