summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Kjernåsen <trond@trolltech.com>2009-09-22 10:37:34 (GMT)
committerTrond Kjernåsen <trond@trolltech.com>2009-09-22 10:40:37 (GMT)
commit66ae0f190f1f07ce7b2578b81f8d0c69328cf028 (patch)
tree36943b60f1cc5211aa356a897bab2f4679f510b1
parent717f6ee081fdfcb7d028e3e26d252f9537878899 (diff)
downloadQt-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
-rw-r--r--src/gui/text/qfontengine_ft.cpp6
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp46
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h2
3 files changed, 35 insertions, 19 deletions
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index a4b2e7e..788417a 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -647,8 +647,14 @@ bool QFontEngineFT::init(FaceId faceId, bool antialias, GlyphFormat format)
{
defaultFormat = format;
this->antialias = antialias;
+
if (!antialias)
glyphFormat = QFontEngineGlyphCache::Raster_Mono;
+ else if (format == Format_A8)
+ glyphFormat = QFontEngineGlyphCache::Raster_A8;
+ else if (format == Format_A32)
+ glyphFormat = QFontEngineGlyphCache::Raster_RGBMask;
+
face_id = faceId;
freetype = QFreetypeFace::getFace(face_id);
if (!freetype) {
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