Skip to content

Commit

Permalink
generate-glyph-info: Fix double entries
Browse files Browse the repository at this point in the history
[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 <[email protected]>
  • Loading branch information
Finii committed Mar 17, 2024
1 parent 6932ff2 commit 2fa4598
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 18 additions & 5 deletions bin/scripts/generate-glyph-info-from-set.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -66,9 +66,13 @@
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("-", "_")
Expand All @@ -78,9 +82,18 @@
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))
1 change: 0 additions & 1 deletion bin/scripts/lib/i_cod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2fa4598

Please sign in to comment.