tags:

views:

42

answers:

2

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.

A: 

A possible solution...


Depending upon your application the following might be a possible solution
(or completetly not applicable) :

  • Popup a dialog-box with a sample paragraph containing all the characters that you intend to use.

  • Render the paragraph using the FONT u have in mind.

  • Display a message to the user to

    -- Select OK (if he/she can read the text i.e. only if no "squares" visible)

    -- Select a different FONT (if any "squares" are visible)

NOTE: In case you are wondering, this is not a very uncommon behaviour for apps. MS-WORD does this when it detects non-standard encoding in a doc file.

GoodLUCK!!

CVS-2600Hertz
A: 

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

Tatu Lahtela