From 2fa45981ee4b46eded3ceee3e4a5100fee442786 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Sun, 17 Mar 2024 14:21:15 +0100 Subject: [PATCH] generate-glyph-info: Fix double entries [why] Two glyphs may not have the same name (normally). Our glyphnames.json will break. [how] Do not add two entries with the same name but rather report the codepoints in the bottom. Signed-off-by: Fini Jastrow --- bin/scripts/generate-glyph-info-from-set.py | 23 ++++++++++++++++----- bin/scripts/lib/i_cod.sh | 1 - 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bin/scripts/generate-glyph-info-from-set.py b/bin/scripts/generate-glyph-info-from-set.py index bbf8f0a10..82dd7da93 100755 --- a/bin/scripts/generate-glyph-info-from-set.py +++ b/bin/scripts/generate-glyph-info-from-set.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # coding=utf8 # Nerd Fonts Version: 3.1.1 -# Script Version: 1.1.1 +# Script Version: 1.2.0 # Example Usage: # ./generate-glyph-info-from-set.py --font ../../src/glyphs/materialdesignicons-webfont.ttf --start f001 --end f847 --offset 4ff --prefix mdi @@ -66,9 +66,13 @@ elif args.symbolOffset: signedOffset = int(sign+'0x'+format(offset, 'X'), 16) hexPosition = args.symbolFontStart + signedOffset -symbolFont.selection.select((str("ranges"),str("unicode")),args.symbolFontStart,args.symbolFontEnd) - -for index, sym_glyph in enumerate(symbolFont.selection.byGlyphs): +allNames = {} +suppressedEntries = [] +symbolFont.encoding = 'UnicodeFull' +for index in range(args.symbolFontStart, args.symbolFontEnd + 1): + if not index in symbolFont: + continue + sym_glyph = symbolFont[index] slot = format(sym_glyph.unicode, 'X') name = sym_glyph.glyphname sh_name = "i_" + args.prefix + "_" + name.replace("-", "_") @@ -78,9 +82,18 @@ for index, sym_glyph in enumerate(symbolFont.selection.byGlyphs): else: char = chr(int('0x'+slot, 16) + signedOffset) - print("i='" + char + "' " + sh_name + "=$i") + entryString = "i='" + char + "' " + sh_name + "=$i SLOT " + slot + ' ' + str(index) + if name not in allNames: + print(entryString) + else: + suppressedEntries.append(entryString) + ctr += 1 hexPosition += 1 + allNames[name] = 1 print("Done, generated " + str(ctr) + " glyphs") +if len(suppressedEntries) > 0: + print('FOLLOGING ENTRIES SUPPRESSED to prevent double names with different codepoints:') + print('\n'.join(suppressedEntries)) diff --git a/bin/scripts/lib/i_cod.sh b/bin/scripts/lib/i_cod.sh index d8e44262b..73fcd988b 100644 --- a/bin/scripts/lib/i_cod.sh +++ b/bin/scripts/lib/i_cod.sh @@ -151,7 +151,6 @@ i='' i_cod_folder_opened=$i i='' i_cod_gear=$i i='' i_cod_gift=$i i='' i_cod_gist_secret=$i -i='' i_cod_file_code=$i i='' i_cod_git_commit=$i i='' i_cod_git_compare=$i i='' i_cod_git_merge=$i