Does anyone know if it's possible to build Qt5 with FreeType as the text renderer on Windows instead of the native one? I tried compiling Qt5 with -qt-freetype but I still get bad text. Do I have to do something else?
问题:
回答1:
When looking at the solution proposed by DeadWarlock I studied the Qt source code and realized that QWindowsFontDatabaseFT is created and used when d->m_options & QWindowsIntegration::FontDatabaseFreeType
is true
. After a bit of googling I found out that turning this option on is officially documented in Qt. The option can be turned on by creating file qt.conf
. The file must be located in the directory containing the application executable and must contain following content:
[Platforms]
WindowsArguments = fontengine=freetype
After doing this I got freetype rendering without recompiling of Qt.
回答2:
Qt with freetype - Honestly, it's a big pain in the ass. Because even if you turn on it. The output glyphs will not look properly as in naked freetype, they make some changes. But any way they look better compared to default realization. I know only one way to do it (very bad advice and maybe not legal do not do this please).
Find file: %qt-src%\qtbase\src\plugins\platforms\windows\qwindowsintegration.cpp. Here a part code from that file where need make changes:
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;
}
I give you a hint - QWindowsFontDatabaseFT never will be created under Windows. I do not remember exactly maybe need add changes in some other places. Last time when I makes this was long time ago in my home project. But now you know in which way need dig.
P.S.
If find another solution, please write here. Thanks.