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>
This commit is contained in:
Allan Sandfeld Jensen 2014-07-24 14:33:00 +02:00
parent 86789a48f7
commit 7ff4621100
5 changed files with 15 additions and 2 deletions

View File

@ -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.

View File

@ -83,6 +83,7 @@ public:
NoAntialias = 0x0100,
OpenGLCompatible = 0x0200,
ForceIntegerMetrics = 0x0400,
NoSubpixelAntialias = 0x0800,
NoFontMerging = 0x8000
};

View File

@ -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)

View File

@ -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);
}

View File

@ -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;