From 35bdd8942716c716113e5b795186ca76199e8d96 Mon Sep 17 00:00:00 2001 From: Trond Kjernaasen Date: Fri, 5 Jun 2009 12:32:51 +0200 Subject: Fixed text drawing on Windows in 16 bit mode. There were several problems with antialiased text in 16 bit mode under Windows. No gamma correction was done, yet we prepared the cached glyphs for gamma correction. The mask format we rendered the glyphs into was also set to the desktop depth, which implied that information was lost and the text looked rather odd. Reviewed-by: Samuel BT: yes --- src/gui/text/qfontengine_win.cpp | 26 ++++++++++++++------------ src/gui/text/qfontengine_win_p.h | 3 ++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp index 7341665..dc2e1ff 100644 --- a/src/gui/text/qfontengine_win.cpp +++ b/src/gui/text/qfontengine_win.cpp @@ -1335,7 +1335,7 @@ bool QFontEngineWin::getSfntTableData(uint tag, uchar *buffer, uint *length) con QNativeImage *QFontEngineWin::drawGDIGlyph(HFONT font, glyph_t glyph, int margin, - const QTransform &t) + const QTransform &t, QImage::Format mask_format) { glyph_metrics_t gm = boundingBox(glyph); @@ -1408,7 +1408,7 @@ QNativeImage *QFontEngineWin::drawGDIGlyph(HFONT font, glyph_t glyph, int margin QNativeImage *ni = new QNativeImage(iw + 2 * margin + 4, ih + 2 * margin + 4, - QNativeImage::systemFormat(), true); + mask_format, true); ni->image.fill(0xffffffff); HDC hdc = ni->hdc; @@ -1448,8 +1448,12 @@ QImage QFontEngineWin::alphaMapForGlyph(glyph_t glyph, const QTransform &xform) lf.lfQuality = ANTIALIASED_QUALITY; font = CreateFontIndirectW(&lf); } + QImage::Format mask_format = QNativeImage::systemFormat(); +#ifndef Q_OS_WINCE + mask_format = QImage::Format_RGB32; +#endif - QNativeImage *mask = drawGDIGlyph(font, glyph, 0, xform); + QNativeImage *mask = drawGDIGlyph(font, glyph, 0, xform, mask_format); if (mask == 0) return QImage(); @@ -1466,22 +1470,20 @@ QImage QFontEngineWin::alphaMapForGlyph(glyph_t glyph, const QTransform &xform) // Alpha channel of the ni.image pixels... for (int y=0; yheight(); ++y) { uchar *dest = indexed.scanLine(y); - if (mask->systemFormat() == QImage::Format_RGB16) { + if (mask->image.format() == QImage::Format_RGB16) { const qint16 *src = (qint16 *) ((const QImage &) mask->image).scanLine(y); - for (int x=0; xwidth(); ++x) { -#ifdef Q_OS_WINCE + for (int x=0; xwidth(); ++x) dest[x] = 255 - qGray(src[x]); -#else - dest[x] = 255 - (qt_pow_gamma[qGray(src[x])] * 255. / 2047.); -#endif - } } else { const uint *src = (uint *) ((const QImage &) mask->image).scanLine(y); for (int x=0; xwidth(); ++x) { #ifdef Q_OS_WINCE dest[x] = 255 - qGray(src[x]); #else - dest[x] = 255 - (qt_pow_gamma[qGray(src[x])] * 255. / 2047.); + if (QNativeImage::systemFormat() == QImage::Format_RGB16) + dest[x] = 255 - qGray(src[x]); + else + dest[x] = 255 - (qt_pow_gamma[qGray(src[x])] * 255. / 2047.); #endif } } @@ -1507,7 +1509,7 @@ QImage QFontEngineWin::alphaRGBMapForGlyph(glyph_t glyph, int margin, const QTra SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &contrast, 0); SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, (void *) 1000, 0); - QNativeImage *mask = drawGDIGlyph(font, glyph, margin, t); + QNativeImage *mask = drawGDIGlyph(font, glyph, margin, t, QImage::Format_RGB32); SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, (void *) contrast, 0); if (mask == 0) diff --git a/src/gui/text/qfontengine_win_p.h b/src/gui/text/qfontengine_win_p.h index 6f37e91..f78bc6a 100644 --- a/src/gui/text/qfontengine_win_p.h +++ b/src/gui/text/qfontengine_win_p.h @@ -138,7 +138,8 @@ public: mutable int designAdvancesSize; private: - QNativeImage *drawGDIGlyph(HFONT font, glyph_t, int margin, const QTransform &xform); + QNativeImage *drawGDIGlyph(HFONT font, glyph_t, int margin, const QTransform &xform, + QImage::Format mask_format); }; -- cgit v0.12