From 34e560fc928d2b0fb78cff60f690f3094ec36ac0 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Wed, 5 Mar 2014 11:13:02 +0200 Subject: [PATCH] Optimize QFontEngineMulti::stringToCMap() in case of missing glyphs Use recently introduced glyphIndex() method and only recalc advances if the glyph is present in the font. This allows to avoid restoring the old advance when the glyph was not found in the fallback fonts. Change-Id: I3e0aa549961767e5448816327328101cf6a78873 Reviewed-by: Lars Knoll --- src/gui/text/qfontengine.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 87d3090a39..a5f213113d 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -1600,9 +1600,6 @@ bool QFontEngineMulti::stringToCMap(const QChar *str, int len, bool surrogate = (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()); uint ucs4 = surrogate ? QChar::surrogateToUcs4(str[i], str[i+1]) : str[i].unicode(); if (glyphs->glyphs[glyph_pos] == 0 && str[i].category() != QChar::Separator_Line) { - QFixed tmpAdvance; - if (!(flags & GlyphIndicesOnly)) - tmpAdvance = glyphs->advances[glyph_pos]; for (int x = 1, n = qMin(engines.size(), 256); x < n; ++x) { if (engines.at(x) == 0 && !shouldLoadFontEngineForCharacter(x, ucs4)) continue; @@ -1616,23 +1613,18 @@ bool QFontEngineMulti::stringToCMap(const QChar *str, int len, if (engine->type() == Box) continue; - if (!(flags & GlyphIndicesOnly)) - glyphs->advances[glyph_pos] = QFixed(); - int num = 2; - QGlyphLayout g = glyphs->mid(glyph_pos, num); - if (!engine->stringToCMap(str + i, surrogate ? 2 : 1, &g, &num, flags)) - Q_UNREACHABLE(); - Q_ASSERT(num == 1); - if (glyphs->glyphs[glyph_pos]) { + glyph_t glyph = engine->glyphIndex(ucs4); + if (glyph != 0) { + glyphs->glyphs[glyph_pos] = glyph; + if (!(flags & GlyphIndicesOnly)) { + QGlyphLayout g = glyphs->mid(glyph_pos, 1); + engine->recalcAdvances(&g, flags); + } // set the high byte to indicate which engine the glyph came from glyphs->glyphs[glyph_pos] |= (x << 24); break; } } - - // ensure we use metrics from the 1st font when we use the fallback image. - if (!(flags & GlyphIndicesOnly) && glyphs->glyphs[glyph_pos] == 0) - glyphs->advances[glyph_pos] = tmpAdvance; } if (surrogate)