-
How can I find out if an font support an character? For example, I wanna know if this font.zip support the glyph I have try this, but it doesn't work: from fontTools.ttLib.ttFont import TTFont
def is_glyph_supported(font: TTFont, glyph: str):
if len(glyph) != 1:
raise Exception("Glyph need to be 1 character.")
for table in font["cmap"].tables:
if ord(glyph) in table.cmap:
return True
return False
font = TTFont("test.ttf")
print(is_glyph_supported(font, "ë")) # it return me false when it should return true I have also try this, but it also doesn't work: from fontTools.ttLib.ttFont import TTFont
from fontTools.misc.encodingTools import getEncoding
def is_glyph_supported(font: TTFont, glyph: str):
if len(glyph) != 1:
raise Exception("Glyph need to be 1 character.")
for table in font["cmap"].tables:
if (glyph).encode(getEncoding(table.platformID, table.platEncID, table.language)) in table.cmap:
return True
return False
font = TTFont("test.ttf")
print(is_glyph_supported(font, "ë")) # it return me false when it should return true |
Beta Was this translation helpful? Give feedback.
Answered by
moi15moi
Feb 21, 2023
Replies: 1 comment 27 replies
-
You can get the character map this way: from fontTools.ttLib import TTFont
f = TTFont(font_path)
cmap = f.getBestCmap() |
Beta Was this translation helpful? Give feedback.
27 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, I did not understood that the codepoints were already good, but it was only the name that wasn't.
I should have verified earlier that the glyph were already by creating an svg for each glyph and verify them: