How do I extract the list of supported Unicode characters from a TrueType or embedded OpenType font on Linux?
Is there a tool or a library I can use to process a .ttf or a .eot file and build a list of code points (like U+0123, U+1234, etc.) provided by the font?
Try pasting the copied text/symbol into a blank Microsoft Word doc. The content should appear properly if Word is set to Keep Source Formatting by default for pasted text. If so, select the content and the Word font menu will show you the source font on your computer that contains the necessary character.
Right-click your font and select Properties . Select the tab "CharSet/Unicode". If the Font Encoding Type is not Symbol and the Supported Unicode Ranges list anything besides or in addition to Basic Latin and Latin-1 Supplement, your font is a Unicode font or is compatible with Unicode.
Here is a method using the fontTools Python library (which you can install with something like pip install fonttools
):
#!/usr/bin/env python from itertools import chain import sys from fontTools.ttLib import TTFont from fontTools.unicode import Unicode with TTFont( sys.argv[1], 0, allowVID=0, ignoreDecompileErrors=True, fontNumber=-1 ) as ttf: chars = chain.from_iterable( [y + (Unicode[y[0]],) for y in x.cmap.items()] for x in ttf["cmap"].tables ) if len(sys.argv) == 2: # print all code points for c in chars: print(c) elif len(sys.argv) >= 3: # search code points / characters code_points = {c[0] for c in chars} for i in sys.argv[2:]: code_point = int(i) # search code point #code_point = ord(i) # search character print(Unicode[code_point]) print(code_point in code_points)
The script takes as arguments the font path and optionally code points / characters to search for:
$ python checkfont.py /usr/share/fonts/**/DejaVuSans.ttf (32, 'space', 'SPACE') (33, 'exclam', 'EXCLAMATION MARK') (34, 'quotedbl', 'QUOTATION MARK') … $ python checkfont.py /usr/share/fonts/**/DejaVuSans.ttf 65 12622 # a ㅎ LATIN CAPITAL LETTER A True HANGUL LETTER HIEUH False
The X program xfd can do this. To see all characters for the "DejaVu Sans Mono" font, run:
xfd -fa "DejaVu Sans Mono"
It's included in the x11-utils package on Debian/Ubuntu, xorg-x11-apps on Fedora/RHEL, and xorg-xfd on Arch Linux.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With