From 06e8d0cae3651beaf95de05e89696cbab4978740 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 6 Apr 2010 16:23:34 +0200 Subject: Fix painting artifacts on text The height of the row is not only decided by the maximum height of the set of glyphs currently being added to the glyph cache, but also the height of the glyphs previously added to the current line in the glyph cache. To minimize the space used, we now calculate the maximum height for glyphs per line, and use this as the vertical advancement when positioning the next line in the cache. The change also removes a redundant test ((c_x + c.w > c.h) is caught earlier on and will always be false at this point.) Task-number: QTBUG-9176 Reviewed-by: Trond --- src/gui/painting/qtextureglyphcache.cpp | 14 +++++--------- src/gui/painting/qtextureglyphcache_p.h | 3 ++- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp index cf545be..9eda0ef 100644 --- a/src/gui/painting/qtextureglyphcache.cpp +++ b/src/gui/painting/qtextureglyphcache.cpp @@ -133,10 +133,13 @@ void QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const while (iter != listItemCoordinates.end()) { Coord c = iter.value(); + m_currentRowHeight = qMax(m_currentRowHeight, c.h + margin * 2); + if (m_cx + c.w > m_w) { // no room on the current line, start new glyph strip m_cx = 0; - m_cy += rowHeight; + m_cy += m_currentRowHeight; + m_currentRowHeight = 0; // New row } if (m_cy + c.h > m_h) { int new_height = m_h*2; @@ -153,14 +156,7 @@ void QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const fillTexture(c, iter.key()); coords.insert(iter.key(), c); - if (m_cx + c.w > m_w) { - m_cx = 0; - m_cy += rowHeight; - } else { - // for the Mono case, glyph_width is 8-bit aligned, - // and therefore so will m_cx - m_cx += c.w; - } + m_cx += c.w; ++iter; } diff --git a/src/gui/painting/qtextureglyphcache_p.h b/src/gui/painting/qtextureglyphcache_p.h index 803e71b..8c2f5b4 100644 --- a/src/gui/painting/qtextureglyphcache_p.h +++ b/src/gui/painting/qtextureglyphcache_p.h @@ -77,7 +77,7 @@ class Q_GUI_EXPORT QTextureGlyphCache : public QFontEngineGlyphCache public: QTextureGlyphCache(QFontEngineGlyphCache::Type type, const QTransform &matrix) : QFontEngineGlyphCache(matrix, type), m_current_fontengine(0), - m_w(0), m_h(0), m_cx(0), m_cy(0) + m_w(0), m_h(0), m_cx(0), m_cy(0), m_currentRowHeight(0) { } virtual ~QTextureGlyphCache() { } @@ -120,6 +120,7 @@ protected: int m_h; // image height int m_cx; // current x int m_cy; // current y + int m_currentRowHeight; // Height of last row }; -- cgit v0.12