diff options
author | Trond Kjernåsen <trond@trolltech.com> | 2009-09-22 10:37:34 (GMT) |
---|---|---|
committer | Trond Kjernåsen <trond@trolltech.com> | 2009-09-22 10:40:37 (GMT) |
commit | 66ae0f190f1f07ce7b2578b81f8d0c69328cf028 (patch) | |
tree | 36943b60f1cc5211aa356a897bab2f4679f510b1 /src/opengl | |
parent | 717f6ee081fdfcb7d028e3e26d252f9537878899 (diff) | |
download | Qt-66ae0f190f1f07ce7b2578b81f8d0c69328cf028.zip Qt-66ae0f190f1f07ce7b2578b81f8d0c69328cf028.tar.gz Qt-66ae0f190f1f07ce7b2578b81f8d0c69328cf028.tar.bz2 |
Fixed text drawing in the GL2 engine after sub-pixel hinting was added.
1. The mono format was not handled at all.
2. We really, really wanted to use sub-pixel hinted glyphs even
when they were not available.
3. The glyphFormat type in the FT font engine wasn't updated to
reflect the correct system glyph type.
Reviewed-by: Kim
Diffstat (limited to 'src/opengl')
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 46 | ||||
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h | 2 |
2 files changed, 29 insertions, 19 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index fb493e6..eba8844 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -289,9 +289,18 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height) void QGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph) { QImage mask = textureMapForGlyph(glyph); + const int maskWidth = mask.width(); + const int maskHeight = mask.height(); + + if (mask.format() == QImage::Format_Mono) { + mask = mask.convertToFormat(QImage::Format_Indexed8); + for (int y = 0; y < maskHeight; ++y) { + uchar *src = (uchar *) mask.scanLine(y); + for (int x = 0; x < maskWidth; ++x) + src[x] = -src[x]; + } + } - const uint maskWidth = mask.width(); - const uint maskHeight = mask.height(); glBindTexture(GL_TEXTURE_2D, m_texture); if (mask.format() == QImage::Format_RGB32) { @@ -309,7 +318,7 @@ void QGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph) // by converting it to a format with four bytes per pixel. Another is to copy one line at a // time. - for (uint i = 0; i < maskHeight; ++i) + for (int i = 0; i < maskHeight; ++i) glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y + i, maskWidth, 1, GL_ALPHA, GL_UNSIGNED_BYTE, mask.scanLine(i)); #endif } @@ -1226,21 +1235,27 @@ void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem if (ti.fontEngine->fontDef.pixelSize * qSqrt(s->matrix.determinant()) >= 64) drawCached = false; - if (d->glyphCacheType == QFontEngineGlyphCache::Raster_RGBMask + QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0 + ? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat) + : d->glyphCacheType; + + if (glyphType == QFontEngineGlyphCache::Raster_RGBMask && state()->composition_mode != QPainter::CompositionMode_Source - && state()->composition_mode != QPainter::CompositionMode_SourceOver) { + && state()->composition_mode != QPainter::CompositionMode_SourceOver) + { drawCached = false; } if (drawCached) { - d->drawCachedGlyphs(p, ti); + d->drawCachedGlyphs(p, glyphType, ti); return; } QPaintEngineEx::drawTextItem(p, ti); } -void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti) +void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, QFontEngineGlyphCache::Type glyphType, + const QTextItemInt &ti) { Q_Q(QGL2PaintEngineEx); QOpenGL2PaintEngineState *s = q->state(); @@ -1250,10 +1265,6 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextIte QTransform matrix = QTransform::fromTranslate(p.x(), p.y()); ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); - QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0 - ? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat) - : glyphCacheType; - QGLTextureGlyphCache *cache = (QGLTextureGlyphCache *) ti.fontEngine->glyphCache(ctx, s->matrix); @@ -1300,13 +1311,7 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextIte QBrush pensBrush = q->state()->pen.brush(); setBrush(&pensBrush); - if (glyphType == QFontEngineGlyphCache::Raster_A8) { - - // Greyscale antialiasing - - shaderManager->setMaskType(QGLEngineShaderManager::PixelMask); - prepareForDraw(false); // Text always causes src pixels to be transparent - } else if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { + if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { // Subpixel antialiasing without gamma correction @@ -1380,6 +1385,11 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextIte glBlendFunc(GL_ONE, GL_ONE); } compositionModeDirty = true; + } else { + // Greyscale/mono glyphs + + shaderManager->setMaskType(QGLEngineShaderManager::PixelMask); + prepareForDraw(false); // Text always causes src pixels to be transparent } //### TODO: Gamma correction diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h index 049994f..738626f 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h @@ -182,7 +182,7 @@ public: void fill(const QVectorPath &path); void drawOutline(const QVectorPath& path); void drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern = false); - void drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti); + void drawCachedGlyphs(const QPointF &p, QFontEngineGlyphCache::Type glyphType, const QTextItemInt &ti); void drawVertexArrays(QGL2PEXVertexArray& vertexArray, GLenum primitive); // ^ draws whatever is in the vertex array |