How to check if font do support characters (codepoints?)
-
I would like to know if the currently selected font do support a specific character (or string) or if it just renders it with the rectangle-characters like this □□□□□.
Can I check this somehow on the fly while my PyQt5 application is running?
label = QLabel('string to check')
label.rendered?Or "asking" the font:
label.font.codepoints_available('string to check') -
Caveats: On a day-to-day basis I work in C++ and rarely in python. Furthermore, I have not attempted any of what I am sharing here.
However, it seems that using the lower-level C libraries like libfreetype and/or harfbuzz, this is possible. So it seems likely to me that someone has created a python wrapper of some kind that would expose it in python.
Apparently (in C), the libfreetype function
FT_Get_Char_Index
will return0
if the desired glyph does not exist in a given font:And here is an example of someone using
pyharfbuzz
in a similar way: