diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2009-05-06 09:58:56 (GMT) |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2009-05-06 13:04:43 (GMT) |
commit | 2043637a4e17252062fcb483e2e63ce0cb0920dd (patch) | |
tree | 6b6d8c90298f10bbfbf20dda6f81a1aba9819e9c /src/gui/text/qfontengine.cpp | |
parent | 3cec5ff3f0aa8d3eca0dfb325e83a8a3a18cb305 (diff) | |
download | Qt-2043637a4e17252062fcb483e2e63ce0cb0920dd.zip Qt-2043637a4e17252062fcb483e2e63ce0cb0920dd.tar.gz Qt-2043637a4e17252062fcb483e2e63ce0cb0920dd.tar.bz2 |
Re-enabled antialiasing for large font sizes in OpenGL paint engine.
In 4.4 alphaMapForGlyph() would return valid images for any font size,
but this was changed in 4.5, forcing us to use the path fallback
instead. This lead to non-antialiased fonts when not using a
multisample-enabled GL format. This patch re-introduces the
alphaMapForGlyph() fallback in QFontEngine from 4.4 which uses the
raster paint engine to draw the glyph.
Task-number: 247083
Reviewed-by: Trond
Diffstat (limited to 'src/gui/text/qfontengine.cpp')
-rw-r--r-- | src/gui/text/qfontengine.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 47fe5c2..d7a9c23 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -624,6 +624,45 @@ QImage QFontEngine::alphaRGBMapForGlyph(glyph_t glyph, int /* margin */, const Q return rgbMask; } +QImage QFontEngine::alphaMapForGlyph(glyph_t glyph) +{ + glyph_metrics_t gm = boundingBox(glyph); + int glyph_x = qFloor(gm.x.toReal()); + int glyph_y = qFloor(gm.y.toReal()); + int glyph_width = qCeil((gm.x + gm.width).toReal()) - glyph_x; + int glyph_height = qCeil((gm.y + gm.height).toReal()) - glyph_y; + + if (glyph_width <= 0 || glyph_height <= 0) + return QImage(); + QFixedPoint pt; + pt.x = 0; + pt.y = -glyph_y; // the baseline + QPainterPath path; + QImage im(glyph_width + qAbs(glyph_x) + 4, glyph_height, QImage::Format_ARGB32_Premultiplied); + im.fill(Qt::transparent); + QPainter p(&im); + p.setRenderHint(QPainter::Antialiasing); + addGlyphsToPath(&glyph, &pt, 1, &path, 0); + p.setPen(Qt::NoPen); + p.setBrush(Qt::black); + p.drawPath(path); + p.end(); + + QImage indexed(im.width(), im.height(), QImage::Format_Indexed8); + QVector<QRgb> colors(256); + for (int i=0; i<256; ++i) + colors[i] = qRgba(0, 0, 0, i); + indexed.setColorTable(colors); + + for (int y=0; y<im.height(); ++y) { + uchar *dst = (uchar *) indexed.scanLine(y); + uint *src = (uint *) im.scanLine(y); + for (int x=0; x<im.width(); ++x) + dst[x] = qAlpha(src[x]); + } + + return indexed; +} void QFontEngine::removeGlyphFromCache(glyph_t) { |