From 46d2d05e3a95eefae1c72f55d57cbea4ce27d14e Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Wed, 10 Nov 2010 14:18:08 +0100 Subject: Support glyph subpixel positioning without subpixel rendering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously subpixel positioning was only used when subpixel rendering is enabled (glyphType == Raster_RGBMask), however, it does not necessarily require that and for Mac OS X it will keep using subpixel positioning even when LCD font smoothing (subpixel rendering) is turned off. To maintain consistency when switching to raster, we should support subpixel positioning in this case. Task-number: QTBUG-5053 Reviewed-by: Jørgen Lind --- src/gui/painting/qtextureglyphcache.cpp | 2 +- src/gui/text/qfontengine.cpp | 5 +++++ src/gui/text/qfontengine_mac.mm | 4 ++-- src/gui/text/qfontengine_p.h | 3 ++- tests/auto/qpainter/tst_qpainter.cpp | 26 -------------------------- 5 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp index 78c1019..4a6c03f 100644 --- a/src/gui/painting/qtextureglyphcache.cpp +++ b/src/gui/painting/qtextureglyphcache.cpp @@ -312,7 +312,7 @@ QImage QTextureGlyphCache::textureMapForGlyph(glyph_t g, QFixed subPixelPosition if (m_type == QFontEngineGlyphCache::Raster_RGBMask) return m_current_fontengine->alphaRGBMapForGlyph(g, subPixelPosition, glyphMargin(), m_transform); else - return m_current_fontengine->alphaMapForGlyph(g, m_transform); + return m_current_fontengine->alphaMapForGlyph(g, subPixelPosition, m_transform); return QImage(); } diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index f73b816..816c14a 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -607,6 +607,11 @@ void QFontEngine::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int n QImage QFontEngine::alphaMapForGlyph(glyph_t glyph, const QTransform &t) { + return alphaMapForGlyph(glyph, 0, t); +} + +QImage QFontEngine::alphaMapForGlyph(glyph_t glyph, QFixed /*subPixelPosition*/, const QTransform &t) +{ QImage i = alphaMapForGlyph(glyph); if (t.type() > QTransform::TxTranslate) i = i.transformed(t).convertToFormat(QImage::Format_Indexed8); diff --git a/src/gui/text/qfontengine_mac.mm b/src/gui/text/qfontengine_mac.mm index ebc1f6d..cebd1f5 100644 --- a/src/gui/text/qfontengine_mac.mm +++ b/src/gui/text/qfontengine_mac.mm @@ -713,9 +713,9 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition return im; } -QImage QCoreTextFontEngine::alphaMapForGlyph(glyph_t glyph) +QImage QCoreTextFontEngine::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t) { - QImage im = imageForGlyph(glyph, QFixed(), 0, false); + QImage im = imageForGlyph(glyph, subPixelPosition, 0, false); QImage indexed(im.width(), im.height(), QImage::Format_Indexed8); QVector colors(256); diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index 6d6daaa..061bcfd 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -197,6 +197,7 @@ public: */ virtual QImage alphaMapForGlyph(glyph_t); virtual QImage alphaMapForGlyph(glyph_t, const QTransform &t); + virtual QImage alphaMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t); virtual QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, int margin, const QTransform &t); virtual glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, const QTransform &matrix, GlyphFormat /*format*/) @@ -473,7 +474,7 @@ public: virtual FaceId faceId() const; virtual bool getSfntTableData(uint /*tag*/, uchar * /*buffer*/, uint * /*length*/) const; virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics); - virtual QImage alphaMapForGlyph(glyph_t); + virtual QImage alphaMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t); virtual QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, int margin, const QTransform &t); virtual qreal minRightBearing() const; virtual qreal minLeftBearing() const; diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index 42303d2..219f920 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -4581,32 +4581,6 @@ void tst_QPainter::drawText_subPixelPositionsInRaster_qtbug5053() #if !defined(Q_WS_MAC) || !defined(QT_MAC_USE_COCOA) QSKIP("Only Mac/Cocoa supports sub pixel positions in raster engine currently", SkipAll); #endif - - int w = 10, h = 10; - QImage image(w, h, QImage::Format_RGB32); - image.fill(0xffffffff); - QPainter p(&image); - p.drawText(0, h, "X\\"); - p.end(); - - bool foundNonGrayPixel = false; - const int *bits = (const int *) ((const QImage &) image).bits(); - int bpl = image.bytesPerLine() / 4; - for (int y=0; yfont()); QImage baseLine(fm.width(QChar::fromLatin1('e')), fm.height(), QImage::Format_RGB32); -- cgit v0.12