Display all fonts of a single character
Posted: Sun Mar 10, 2019 10:09 pm
That works fantastically. Many thanks too.
If we wish to filter the fonts on the criterium whether they support a given character or not, and output the list in a text file, we may get this list directly and then check the fonts back in Main Type.
We may do that by running this Python script, that we may store in a file called "f.py". It is based on this forum post: https://askubuntu.com/questions/27598/l ... -character, that links to this other forum post: https://apple.stackexchange.com/questio ... -character.
The script is reported to run on macOS, but I ran it on Linux so to use it on a Windows computer we need to install e.g. Ubuntu on a small partition alongside.
Of course the routine called by the script does check only the fonts that it finds on the system that it is running on, so the font files to check must be put at reach. The Windows EULA forbids to use Windows system files outside the licensed installation, but I copied the Windows fonts to Linux only to check them, not to use them. And I’ve already disabled (by renaming it) the .fonts folder in my /home directory (keeping it for further checks) that the Windows font files go into for that purpose.
When checking the Unicode character U+2060 WORD JOINER, we need to type a word joiner from the keyboard into the command line, or paste it into the terminal from the clipboard.
Code: Select all
#!/usr/bin/env python3 # Finds fonts containing a single Unicode character passed as a command line argument. # Supports continuous logging of searched characters, font lists and counts in "out.txt". # Based on the script posted on the following fora: # <https://askubuntu.com/questions/27598/list-of-fonts-containing-selected-character> # <https://apple.stackexchange.com/questions/287707/get-list-of-all-fonts-containing-a-specific-character> # Requirement: python3-fontconfig package. # Syntax: $ python3 <script file name>.py <literal goes here> import sys def find_fonts(c): import fontconfig fonts = fontconfig.query() for path in sorted(fonts): font = fontconfig.FcFont(path) if font.has_char(c): yield path with open('out.txt', 'a') as f: print("\n\nThe Unicode character <", sys.argv, ">",\ hex(ord(sys.argv)), "is supported by these installed fonts:\n", file=f) print("\n\nThe Unicode character <", sys.argv, ">",\ hex(ord(sys.argv)), "is supported by these installed fonts:\n") count = 0 if __name__ == '__main__': import sys search = sys.argv char = search.decode('utf-8') if isinstance(search, bytes) else search for path in find_fonts(char): count += 1 print(count, path, file=f) print(count, path) with open('out.txt', 'a') as f: print("\nThere are", count, "fonts supporting <", sys.argv, ">", hex(ord(sys.argv)), "at reach on this OS.\n", file=f) print("\nThere are", count, "fonts supporting <", sys.argv, ">", hex(ord(sys.argv)), "at reach on this OS.\n")
Among all the fonts shipped with version 1607 of Windows 10, only these few do support the WORD JOINER (that joined the Unicode Standard back in 2002):
I.e. Javanese Text, Microsoft Sans Serif, Myanmar Text, Segoe UI Symbols, and Times New Roman.
Well, that’s it. This weak font support is the more annoying as the word joiner is recommended by Unicode — over the legacy (and now deprecated for this semantics) U+FEFF ZERO WIDTH NO-BREAK SPACE — to prevent undesired line breaks, so that we should use it to make non-breaking spaces out of the many spaces that were encoded in the range U+2002..U+200A and that should be non-breaking but are not, except U+2007 FIGURE SPACE, and except in Donald Knuth’s TeX (that has consistently U+2000 and U+2001 as breaking spaces so that we have both sorts to choose from, rather than two useless duplicates).
OK the last paragraph is a bit off-topic here but exemplifies how we may need to get the fonts listed in a hard-coded way to make sure we didn’t overlook any.