diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp index 0f33cab..5c30b78 100644 --- a/src/opengl/qpaintengine_opengl.cpp +++ b/src/opengl/qpaintengine_opengl.cpp @@ -4799,10 +4799,18 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine, if (it == cache->constEnd()) { // render new glyph and put it in the cache glyph_metrics_t metrics = fontEngine->boundingBox(glyphs[i]); - int glyph_width = qRound(metrics.width.toReal())+2; + int old_glyph_width = qRound(metrics.width.toReal())+2; int glyph_height = qRound(fontEngine->ascent().toReal() + fontEngine->descent().toReal())+2; - if (font_tex->x_offset + glyph_width + x_margin > font_tex->width) { + QImage glyph_im(fontEngine->alphaMapForGlyph(glyphs[i])); + int new_glyph_width = glyph_im.width(); + Q_ASSERT(new_glyph_width >= 0); + // pad the glyph width to an even number + if (new_glyph_width%2 != 0) + ++new_glyph_width; + int glyph_width = qMax(new_glyph_width, old_glyph_width); + + if (font_tex->x_offset + glyph_width + x_margin >= font_tex->width) { int strip_height = qt_next_power_of_two(qRound(fontEngine->ascent().toReal() + fontEngine->descent().toReal())+2); font_tex->x_offset = x_margin; font_tex->y_offset += strip_height; @@ -4832,14 +4840,10 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine, ++it; } } - } + } - QImage glyph_im(fontEngine->alphaMapForGlyph(glyphs[i])); - glyph_width = glyph_im.width(); - Q_ASSERT(glyph_width >= 0); - // pad the glyph width to an even number - if (glyph_width%2 != 0) - ++glyph_width; + if(glyph_width != new_glyph_width) + glyph_width = new_glyph_width; QGLGlyphCoord *qgl_glyph = new QGLGlyphCoord; qgl_glyph->x = qreal(font_tex->x_offset) / font_tex->width; @@ -4890,7 +4894,7 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, tex_data); free(tex_data); } - if (font_tex->x_offset + glyph_width + x_margin > font_tex->width) { + if (font_tex->x_offset + glyph_width + x_margin >= font_tex->width) { font_tex->x_offset = x_margin; font_tex->y_offset += glyph_height + y_margin; } else {