使用 Qt5 在 Windows 上使用 FreeType

use*_*878 5 windows freetype qt5

有谁知道是否可以使用 FreeType 构建 Qt5 作为 Windows 上的文本渲染器而不是本机渲染器?我尝试使用 -qt-freetype 编译 Qt5,但我仍然收到错误的文本。我还需要做些什么吗?

Mar*_*gel 6

在查看 DeadWarlock 提出的解决方案时,我研究了 Qt 源代码,并意识到 QWindowsFontDatabaseFT 是在 时创建和使用d->m_options & QWindowsIntegration::FontDatabaseFreeTypetrue。经过一番谷歌搜索后,我发现启用此选项已在 Qt 中正式记录。可以通过创建 file 来打开该选项qt.conf。该文件必须位于包含应用程序可执行文件的目录中,并且必须包含以下内容:

[Platforms]
WindowsArguments = fontengine=freetype
Run Code Online (Sandbox Code Playgroud)

完成此操作后,我无需重新编译 Qt 即可获得自由类型渲染。


Dea*_*ock 2

Qt 与 freetype - 老实说,这是一个很大的痛苦。因为即使你打开它。输出字形看起来不像裸自由类型那样正确,它们做了一些更改。但无论如何,与默认实现相比,它们看起来更好。我只知道一种方法(非常糟糕的建议,可能不合法,请不要这样做)。

查找文件:%qt-src%\qtbase\src\plugins\platforms\windows\qwindowsintegration.cpp。这是该文件中需要更改的部分代码:

QPlatformFontDatabase *QWindowsIntegration::fontDatabase() const
{
    if (!d->m_fontDatabase) {
#ifdef QT_NO_FREETYPE
        d->m_fontDatabase = new QWindowsFontDatabase();
#else // QT_NO_FREETYPE
        if (d->m_options & QWindowsIntegration::FontDatabaseFreeType) {
            d->m_fontDatabase = new QWindowsFontDatabaseFT;
        } else if (d->m_options & QWindowsIntegration::FontDatabaseNative){
            d->m_fontDatabase = new QWindowsFontDatabase;
        } else {
#ifndef Q_OS_WINCE
            d->m_fontDatabase = new QWindowsFontDatabase;
#else
            if (isQMLApplication()) {
                if (QWindowsContext::verboseIntegration) {
                    qDebug() << "QML application detected, using FreeType rendering";
                }
                d->m_fontDatabase = new QWindowsFontDatabaseFT;
            }
            else
                d->m_fontDatabase = new QWindowsFontDatabase;
#endif
        }
#endif // QT_NO_FREETYPE
    }
    return d->m_fontDatabase;
}
Run Code Online (Sandbox Code Playgroud)

我给你一个提示 - QWindowsFontDatabaseFT永远不会在 Windows 下创建。我不记得了,也许需要在其他一些地方添加更改。我上次做这个是很久以前在我的家庭项目中做的。但现在你知道需要以哪种方式挖掘了。
PS 如果找到其他解决方案,请写在这里。谢谢。