Skip to content

Instantly share code, notes, and snippets.

@chrissimpkins
Created November 7, 2019 19:01
Show Gist options
  • Save chrissimpkins/157762f6bed4fe728e538b8e1eb0aefd to your computer and use it in GitHub Desktop.
Save chrissimpkins/157762f6bed4fe728e538b8e1eb0aefd to your computer and use it in GitHub Desktop.
Unicode hex value checks in cmap tables (fonts)
tt = TTFont(fontpath)
cmap = tt.getBestCmap()
# now the integers are keys in the cmap object and can be used to compare against hexadecimal values for presence in a font
test_list = (hex1, hex2, hex3,...)
# how to split hex ranges to individual hex codes
# e.g., 0x0020-0x0028
for x in range(0x0020,0x0028):
print(hex(x))
for codepoint in test_list:
if int(codepoint) in cmap:
print(True)
else:
print(False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment