Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine whether a QFont supports a certain UTF-8 character

I'm printing some fancy UTF-8 characters, i.e. right arrow 0x2192 and lightning 0x21AF, to a QTextEdit. This works great on a modern operating system like Ubuntu but fails for e.g. Windows XP, since the fonts don't seem to support those UTF-8 characters. Instead, the infamous little placeholder-squares are drawn.

Is there a way to find out, whether the current font of a QFont instance supports a given character, so I can fall back to simpler characters like "-->" for the right arrow?

I've discovered that Qt 4.8 has a QRawFont class, that indeed has a QRawFont::supportsCharacter() method that does exactly what I want, but I can't use 4.8 right now, I'm on 4.6 or 4.7 at best. I've looked at the implementation, and they call QFontEngine::canRender(). However, QFontEngine seems to be a class not accessible from the outside. The only similar sounding classes I can find in 4.7 are QFontEngineInfo and QFontEnginePlugin, both don't seem to provide anything helpful in my case.

like image 662
DerManu Avatar asked Dec 20 '11 00:12

DerManu


1 Answers

canRender is also called by QFontMetrics::inFont(QChar).

like image 98
alexisdm Avatar answered Sep 20 '22 21:09

alexisdm