font-patcher: Fix crash on some custom sets

[why]
When a custom set is to be patched and that set contains the .notdef
glyph the script crashes.

[how]
The glyphs has an unicode codepoint of -1, a code that we explicitely
not patch. That leads to confusion when we try to determine the
codepoint to be used for that glyph, because it has none.

Exclude negative codepoint glyphs when we determine the selection of
to-be-patched glyphs.

As last resort for broken custom sets skip over glyphs that come out of
order (which should be impossible).

Fixes: #1005

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2022-11-26 15:03:51 +01:00 committed by Fini
parent 31f09b9a77
commit dd143be24a

View file

@ -6,7 +6,7 @@
from __future__ import absolute_import, print_function, unicode_literals
# Change the script version when you edit this script:
script_version = "3.2.0"
script_version = "3.2.1"
version = "2.3.0-RC"
projectName = "Nerd Fonts"
@ -925,8 +925,8 @@ class font_patcher:
else:
symbolFont.selection.select((str("ranges"), str("unicode")), symbolFontStart, symbolFontEnd)
# Get number of selected non-empty glyphs
symbolFontSelection = list(symbolFont.selection.byGlyphs)
# Get number of selected non-empty glyphs with codes >=0 (i.e. not -1 == notdef)
symbolFontSelection = [ x for x in symbolFont.selection.byGlyphs if x.unicode >= 0 ]
glyphSetLength = len(symbolFontSelection)
if self.args.quiet is False:
@ -953,6 +953,9 @@ class font_patcher:
possible_codes += [ sym_glyph.unicode ]
if sym_glyph.altuni:
possible_codes += [ v for v, s, r in sym_glyph.altuni if v > currentSourceFontGlyph ]
if len(possible_codes) == 0:
print(" Can not determine codepoint of {:X}. Skipping...".format(sym_glyph.unicode))
continue
currentSourceFontGlyph = min(possible_codes)
else:
# use source font defined hex values based on passed in start (fills gaps; symbols are packed)