diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2014-03-03 03:01:14 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-03 11:11:24 +0100 |
commit | af74201edbb9dc344419ed3f8ebc35f8e8f05617 (patch) | |
tree | 3042ca9a1dc7c319bd60e0346a6a427320e721dc /src/gui/text/qfontengine.cpp | |
parent | 78d115f8f28a7e3f15c0280e8d87d7041ecff793 (diff) |
Introduce QFontEngine::glyphIndex(uint)
...an optimized drop-in replacement for the code like this:
`stringToCMap(&uc, 1, &g, &numGlyphs, QFontEngine::GlyphIndicesOnly)`
(aka "get the glyph index for exactly one Unicode character").
Change-Id: I22babf49f7cf28892d27533a5ac51ad449779f75
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/gui/text/qfontengine.cpp')
-rw-r--r-- | src/gui/text/qfontengine.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 6f62d24f1e..61816c83fb 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -1408,6 +1408,12 @@ QFontEngineBox::~QFontEngineBox() { } +glyph_t QFontEngineBox::glyphIndex(uint ucs4) const +{ + Q_UNUSED(ucs4) + return 0; +} + bool QFontEngineBox::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QFontEngine::ShaperFlags flags) const { Q_ASSERT(glyphs->numGlyphs >= *nglyphs); @@ -1582,6 +1588,35 @@ QFontEngineMulti::~QFontEngineMulti() } } +glyph_t QFontEngineMulti::glyphIndex(uint ucs4) const +{ + glyph_t glyph = engine(0)->glyphIndex(ucs4); + if (glyph == 0 && ucs4 != QChar::LineSeparator) { + const_cast<QFontEngineMulti *>(this)->ensureFallbackFamiliesQueried(); + for (int x = 1, n = qMin(engines.size(), 256); x < n; ++x) { + QFontEngine *engine = engines.at(x); + if (!engine) { + if (!shouldLoadFontEngineForCharacter(x, ucs4)) + continue; + const_cast<QFontEngineMulti *>(this)->loadEngine(x); + engine = engines.at(x); + } + Q_ASSERT(engine != 0); + if (engine->type() == Box) + continue; + + glyph = engine->glyphIndex(ucs4); + if (glyph != 0) { + // set the high byte to indicate which engine the glyph came from + glyph |= (x << 24); + break; + } + } + } + + return glyph; +} + bool QFontEngineMulti::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QFontEngine::ShaperFlags flags) const |