Is there a way to detect that all characters are displayed properly with the current font? In some environments and fonts certain characters are replaced with a square symbol.
I'd like to automatically verify that all characters used in the GUI are supported by the current font.
You can find it in the Editing options under the Home tab. Clicking Replace Fonts brings up two dropdown menus, the first of which includes all the fonts used in your deck.
An alternative way to open this window is: Type > Resolve Missing Fonts. Text with missing fonts is highlighted with pink. In the dialog box, you have an opportunity to sync font from Typekit if it is available or click on the Find Fonts button and replace the missing font with the ones available in the system.
Click in the top-right corner of the toolbar. View a list of fonts and styles that are missing or unavailable in this file: Use the dropdown fields below Replacement to update the family and style for each missing font. Figma will only show you fonts available to you.
I found a possible solution using the QFontMetrics class. Here is a an example function to query whether all characters are available in the current text of a QLabel:
bool charactersMissing(const QLabel& label) {
QFontMetrics metrics(label.font());
for (int i = 0; i < label.text().size(); ++i) {
if (!metrics.inFont(label.text().at(i))) {
return true;
}
}
return false;
}
Of course displaying to the user which character is missing would be good, but of course that has to be done with a different font :)
According to this discussion, I don't think the sample code of QFontMetrics will work well. https://bugreports.qt-project.org/browse/QTBUG-1732
The QFontMetrics inFont() function depend on QFont class, and it seems you have to set the StyleStrategy to QFont::NoFontMerging. But actually, the NoFontMerging flag doesn't work in that way you think, so the inFont function still return true if other fonts in your system have this glyph.
BTW, I make a verification tool in python finally.
https://github.com/diro/pyGlyphChecker
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