diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2014-02-03 02:44:46 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-07 15:31:55 +0100 |
commit | 4e319ca4c47a99295c1a07aa759e09d86f1b7c87 (patch) | |
tree | c6e8591798db0e795c9efc60a450927341ad4501 /src/gui/text/qrawfont.cpp | |
parent | 93aec932ff6471b39cd3b577079407f145996ec2 (diff) |
Optimize stringToCMap() usage
CMAP guarantees there is 1:1 mapping between the Unicode code points
array and the glyph indexes array, which means the QString length
always greater than or equal to a sufficient glyph indexes array length.
Simply add some asserts and improve the memory consumption
and the performance where possible.
Change-Id: I0bc8cdba5f86c1c0ba9e79c8d5f96cbe56ec463e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/gui/text/qrawfont.cpp')
-rw-r--r-- | src/gui/text/qrawfont.cpp | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp index e26f7cdc93..449278df06 100644 --- a/src/gui/text/qrawfont.cpp +++ b/src/gui/text/qrawfont.cpp @@ -479,16 +479,8 @@ QVector<quint32> QRawFont::glyphIndexesForString(const QString &text) const QGlyphLayout glyphs; glyphs.numGlyphs = numGlyphs; glyphs.glyphs = glyphIndexes.data(); - if (!d->fontEngine->stringToCMap(text.data(), text.size(), &glyphs, &numGlyphs, QFontEngine::GlyphIndicesOnly)) { - glyphIndexes.resize(numGlyphs); - - glyphs.numGlyphs = numGlyphs; - glyphs.glyphs = glyphIndexes.data(); - if (!d->fontEngine->stringToCMap(text.data(), text.size(), &glyphs, &numGlyphs, QFontEngine::GlyphIndicesOnly)) { - Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice"); - return QVector<quint32>(); - } - } + if (!d->fontEngine->stringToCMap(text.data(), text.size(), &glyphs, &numGlyphs, QFontEngine::GlyphIndicesOnly)) + Q_UNREACHABLE(); glyphIndexes.resize(numGlyphs); return glyphIndexes; @@ -565,10 +557,11 @@ bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *adv if (!d->isValid() || numGlyphs <= 0) return false; + QVarLengthArray<QFixed> tmpAdvances(numGlyphs); + QGlyphLayout glyphs; glyphs.glyphs = const_cast<glyph_t *>(glyphIndexes); glyphs.numGlyphs = numGlyphs; - QVarLengthArray<QFixed> tmpAdvances(numGlyphs); glyphs.advances = tmpAdvances.data(); bool design = layoutFlags & UseDesignMetrics; @@ -578,7 +571,7 @@ bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *adv d->fontEngine->doKerning(&glyphs, design ? QFontEngine::DesignMetrics : QFontEngine::ShaperFlag(0)); for (int i=0; i<numGlyphs; ++i) - advances[i] = QPointF(glyphs.advances[i].toReal(), 0.0); + advances[i] = QPointF(tmpAdvances[i].toReal(), 0.0); return true; } |