summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2014-07-24 14:33:00 +0200
committerAllan Sandfeld Jensen <allan.jensen@digia.com>2014-08-03 16:19:24 +0200
commit7ff4621100b3df7ba9b336ac60204da4b548e642 (patch)
tree4c9349521044a5c39861385abaa40f10987d982b /src
parent86789a48f73ed2d39cce3ff6596e71cb64e547e7 (diff)
Add QFont strategy to disable subpixel antialiasing
This patch adds the option to disable subpixel antialiasing on QFont basis. This can be useful when painting to offscreen surfaces. On OS X this option disables the aggressive LCD font smoothing, which can be necessary for certain fonts it may otherwise ruin. Task-number: QTBUG-40396 Change-Id: I1664b636520ae63ee1503b5df7436748106b9f5c Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/text/qfont.cpp1
-rw-r--r--src/gui/text/qfont.h1
-rw-r--r--src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp4
-rw-r--r--src/plugins/platforms/cocoa/qpaintengine_mac.mm7
-rw-r--r--src/plugins/platforms/windows/qwindowsfontdatabase.cpp4
5 files changed, 15 insertions, 2 deletions
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp
index 31fd9929f9..cf64c89f2f 100644
--- a/src/gui/text/qfont.cpp
+++ b/src/gui/text/qfont.cpp
@@ -1305,6 +1305,7 @@ QFont::StyleHint QFont::styleHint() const
\value PreferOutline prefers outline fonts (as opposed to bitmap fonts).
\value ForceOutline forces the use of outline fonts.
\value NoAntialias don't antialias the fonts.
+ \value NoSubpixelAntialias avoid subpixel antialiasing on the fonts if possible.
\value PreferAntialias antialias if possible.
\value OpenGLCompatible forces the use of OpenGL compatible
fonts.
diff --git a/src/gui/text/qfont.h b/src/gui/text/qfont.h
index 7fbaf24861..f48f4cf4c5 100644
--- a/src/gui/text/qfont.h
+++ b/src/gui/text/qfont.h
@@ -83,6 +83,7 @@ public:
NoAntialias = 0x0100,
OpenGLCompatible = 0x0200,
ForceIntegerMetrics = 0x0400,
+ NoSubpixelAntialias = 0x0800,
NoFontMerging = 0x8000
};
diff --git a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp
index 0d1f9455e1..0c227eda57 100644
--- a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp
+++ b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp
@@ -633,7 +633,9 @@ QFontEngine *QFontconfigDatabase::fontEngine(const QFontDef &f, void *usrPtr)
}
if (antialias) {
- QFontEngineFT::SubpixelAntialiasingType subpixelType = subpixelTypeFromMatch(match);
+ QFontEngineFT::SubpixelAntialiasingType subpixelType = QFontEngineFT::Subpixel_None;
+ if (!(f.styleStrategy & QFont::NoSubpixelAntialias))
+ subpixelType = subpixelTypeFromMatch(match);
engine->subpixelType = subpixelType;
format = (subpixelType == QFontEngineFT::Subpixel_None)
diff --git a/src/plugins/platforms/cocoa/qpaintengine_mac.mm b/src/plugins/platforms/cocoa/qpaintengine_mac.mm
index f4cd071ab7..d48cbdfac8 100644
--- a/src/plugins/platforms/cocoa/qpaintengine_mac.mm
+++ b/src/plugins/platforms/cocoa/qpaintengine_mac.mm
@@ -1084,6 +1084,10 @@ void QCoreGraphicsPaintEngine::drawTextItem(const QPointF &pos, const QTextItem
if (textAA != lineAA)
CGContextSetShouldAntialias(d->hd, textAA);
+ const bool smoothing = textAA && !(fe->fontDef.styleStrategy & QFont::NoSubpixelAntialias);
+ if (d->disabledSmoothFonts == smoothing)
+ CGContextSetShouldSmoothFonts(d->hd, smoothing);
+
if (ti.glyphs.numGlyphs) {
switch (fe->type()) {
case QFontEngine::Mac:
@@ -1100,6 +1104,9 @@ void QCoreGraphicsPaintEngine::drawTextItem(const QPointF &pos, const QTextItem
if (textAA != lineAA)
CGContextSetShouldAntialias(d->hd, !textAA);
+ if (smoothing == d->disabledSmoothFonts)
+ CGContextSetShouldSmoothFonts(d->hd, !d->disabledSmoothFonts);
+
updatePen(oldPen);
updateBrush(oldBrush, oldBrushOrigin);
}
diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp
index 363d8b2d5c..b22c35137d 100644
--- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp
+++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp
@@ -1520,13 +1520,15 @@ LOGFONT QWindowsFontDatabase::fontDefToLOGFONT(const QFontDef &request)
#endif
if (request.styleStrategy & QFont::PreferAntialias) {
- if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP) {
+ if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && !(request.styleStrategy & QFont::NoSubpixelAntialias)) {
qual = CLEARTYPE_QUALITY;
} else {
qual = ANTIALIASED_QUALITY;
}
} else if (request.styleStrategy & QFont::NoAntialias) {
qual = NONANTIALIASED_QUALITY;
+ } else if ((request.styleStrategy & QFont::NoSubpixelAntialias) && sharedFontData()->clearTypeEnabled) {
+ qual = ANTIALIASED_QUALITY;
}
lf.lfQuality = qual;