Get glyph by id?

Hi! Is it possible to get glyph by glyph.id other than iterating over all glyphs and comparing each? font.glyphs[ glyph.id ] would be convenient but gives None

Yes, you can use the pyobjc method described here: GSFont Class Reference

font.glyphForId_(glyph.id)
3 Likes

I knew there’s got to be something like this, thanks!

When adding a new glyph with code, glyphForId_ can’t find it:

glyph = GSGlyph('a')
Font.glyphs.append(glyph)
print(glyph.id)  # 3B62D456-B0AB-4832-AAE2-8D57AE290EF2
print(Font.glyphForId_(glyph.id))  # None

The solution is to reopen the file, but Is there a way to inform Font about the new glyph properly?

I fixed it.
until the fix is out:

glyph = GSGlyph('a')
Font.glyphs.append(glyph)
Font.resetCache()
…
1 Like