Windows QPA: Introduce command line options for DirectWrite

Add option "nodirectwrite" to turn off DirectWrite fonts
and "nocolorfonts" to turn off DirectWrite for colored fonts.

Task-number: QTBUG-55096
Task-number: QTBUG-55097
Change-Id: If12133fbd20dc7657b3616eff833a8e8c116e070
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
Friedemann Kleint 2016-08-03 09:16:03 +02:00
parent ac9d19c986
commit 7f66289f9d
3 changed files with 28 additions and 12 deletions

View File

@ -40,6 +40,7 @@
#include "qwindowsfontdatabase.h"
#include "qwindowsfontdatabase_ft.h" // for default font
#include "qwindowscontext.h"
#include "qwindowsintegration.h"
#include "qwindowsfontengine.h"
#include "qwindowsfontenginedirectwrite.h"
#include "qtwindows_additional.h"
@ -112,6 +113,18 @@ static void createDirectWriteFactory(IDWriteFactory **factory)
*factory = static_cast<IDWriteFactory *>(result);
}
static inline bool useDirectWrite(QFont::HintingPreference hintingPreference, bool isColorFont = false)
{
const unsigned options = QWindowsIntegration::instance()->options();
if (Q_UNLIKELY(options & QWindowsIntegration::DontUseDirectWriteFonts))
return false;
if (isColorFont)
return (options & QWindowsIntegration::DontUseColorFonts) == 0;
return hintingPreference == QFont::PreferNoHinting
|| hintingPreference == QFont::PreferVerticalHinting
|| (QHighDpiScaling::isActive() && hintingPreference == QFont::PreferDefaultHinting);
}
#endif // !QT_NO_DIRECTWRITE
// Helper classes for creating font engines directly from font data
@ -1163,11 +1176,7 @@ QFontEngine *QWindowsFontDatabase::fontEngine(const QByteArray &fontData, qreal
QFontEngine *fontEngine = 0;
#if !defined(QT_NO_DIRECTWRITE)
bool useDirectWrite = (hintingPreference == QFont::PreferNoHinting)
|| (hintingPreference == QFont::PreferVerticalHinting)
|| (QHighDpiScaling::isActive() && hintingPreference == QFont::PreferDefaultHinting);
if (!useDirectWrite)
if (!useDirectWrite(hintingPreference))
#endif
{
GUID guid;
@ -1804,12 +1813,13 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request,
isColorFont = true;
}
#endif
bool useDirectWrite = (request.hintingPreference == QFont::PreferNoHinting)
|| (request.hintingPreference == QFont::PreferVerticalHinting)
|| (QHighDpiScaling::isActive() && request.hintingPreference == QFont::PreferDefaultHinting)
|| isColorFont;
if (useDirectWrite) {
const QFont::HintingPreference hintingPreference =
static_cast<QFont::HintingPreference>(request.hintingPreference);
const bool useDw = useDirectWrite(hintingPreference, isColorFont);
qCDebug(lcQpaFonts) << __FUNCTION__ << request.family << request.pointSize
<< "pt" << "hintingPreference=" << hintingPreference << "color=" << isColorFont
<< dpi << "dpi" << "useDirectWrite=" << useDw;
if (useDw) {
QWindowsFontEngineDirectWrite *fedw = new QWindowsFontEngineDirectWrite(directWriteFontFace,
request.pixelSize,
data);

View File

@ -199,6 +199,10 @@ static inline unsigned parseOptions(const QStringList &paramList,
}
} else if (param == QLatin1String("gl=gdi")) {
options |= QWindowsIntegration::DisableArb;
} else if (param == QLatin1String("nodirectwrite")) {
options |= QWindowsIntegration::DontUseDirectWriteFonts;
} else if (param == QLatin1String("nocolorfonts")) {
options |= QWindowsIntegration::DontUseColorFonts;
} else if (param == QLatin1String("nomousefromtouch")) {
options |= QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch;
} else if (parseIntOption(param, QLatin1String("verbose"), 0, INT_MAX, &QWindowsContext::verbose)

View File

@ -60,7 +60,9 @@ public:
DisableArb = 0x4,
NoNativeDialogs = 0x8,
XpNativeDialogs = 0x10,
DontPassOsMouseEventsSynthesizedFromTouch = 0x20 // Do not pass OS-generated mouse events from touch.
DontPassOsMouseEventsSynthesizedFromTouch = 0x20, // Do not pass OS-generated mouse events from touch.
DontUseDirectWriteFonts = 0x40,
DontUseColorFonts = 0x80
};
explicit QWindowsIntegration(const QStringList &paramList);