Last active
January 5, 2021 12:00
-
-
Save mwgamera/364c4193fb54225b446a to your computer and use it in GitHub Desktop.
List all fonts known to fontconfig that provide glyph for given characters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # klg, May 2014 | |
| import fontconfig | |
| import sys | |
| chars = list(''.join(sys.argv[1:])) | |
| if not len(chars): | |
| sys.exit(0) | |
| fonts = fontconfig.query() | |
| def progress(i): | |
| message = '\rSearching fonts ... {0} / {1} \033[K' | |
| sys.stderr.write(message.format(i, len(fonts))) | |
| sys.stderr.flush() | |
| def clear(): | |
| sys.stderr.write('\r\033[K') | |
| sys.stderr.flush() | |
| for i in range(len(fonts)): | |
| if i % 17 == 0: | |
| progress(i) | |
| x = [ch for ch in chars if fonts[i].has_char(ch)] | |
| if len(x): | |
| x = ' '.join(['{:04X}'.format(ord(ch)) for ch in x]) | |
| path = fonts[i].file | |
| clear() | |
| print('{}: {}'.format(x, path)) | |
| progress(i) | |
| clear() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I stopped using this script long time ago when I realized that fontconfig cache can be queried much more effectively using
fc-list ':charset=XXXX'where XXXX is a hexadecimal Unicode code point, or a comma-separated list of such.