Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect missing font characters

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.

like image 422
Tatu Lahtela Avatar asked Apr 21 '10 08:04

Tatu Lahtela


People also ask

How do I find a missing font in PowerPoint?

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.

How do I find missing fonts in Illustrator?

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.

How do I get missing fonts in Figma?

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.


2 Answers

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 :)

like image 121
Tatu Lahtela Avatar answered Oct 14 '22 07:10

Tatu Lahtela


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

like image 44
diro Avatar answered Oct 14 '22 08:10

diro