确定 QFont 是否支持某个 UTF-8 字符
我正在将一些奇特的 UTF-8 字符(即右箭头 0x2192 和闪电 0x21AF)打印到 QTextEdit。这在 Ubuntu 等现代操作系统上效果很好,但在 Windows XP 等操作系统上却失败了,因为字体似乎不支持那些 UTF-8 字符。相反,绘制了臭名昭著的小占位符方块。
有没有办法查明 QFont 实例的当前字体是否支持给定字符,这样我就可以回退到更简单的字符,例如“-->”对于右箭头?
我发现 Qt 4.8 有一个 QRawFont 类,它确实有一个 QRawFont::supportsCharacter() 方法,它完全符合我的要求,但我现在不能使用 4.8,我最多只能使用 4.6 或 4.7。 我查看了实现,他们调用了 QFontEngine::canRender()。然而,QFontEngine似乎是一个无法从外部访问的类。我在 4.7 中能找到的唯一类似的听起来类是 QFontEngineInfo 和 QFontEnginePlugin,两者似乎对我的情况没有提供任何帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
canRender
也由QFontMetrics::inFont 调用(QChar)
。canRender
is also called byQFontMetrics::inFont(QChar)
.