Skip to content

Commit

Permalink
Windows QPA: Introduce command line options for DirectWrite
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
FriedemannKleint committed Aug 5, 2016
1 parent ac9d19c commit 7f66289
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
32 changes: 21 additions & 11 deletions src/plugins/platforms/windows/qwindowsfontdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/platforms/windows/qwindowsintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/platforms/windows/qwindowsintegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class QWindowsIntegration : public QPlatformIntegration
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);
Expand Down

0 comments on commit 7f66289

Please sign in to comment.