From d8225fab8fb8b21fb5d35968d9edb5340b76bcc2 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Wed, 29 Jan 2014 19:52:41 +0200 Subject: [QFontEngineBox] Fix incorrect advances for SMP code points In UTF-16, SMP code point is encoded with a pair of surrogates, thus making SMP code point twice wider than BMP code point. Change-Id: Ifb0e78cff50cca7231d07097a730188bd98c54cb Reviewed-by: Lars Knoll --- src/gui/text/qfontengine.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/gui/text') diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 7dfd9423e9..a3fce197ce 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -1299,17 +1299,24 @@ QFontEngineBox::~QFontEngineBox() { } -bool QFontEngineBox::stringToCMap(const QChar *, int len, QGlyphLayout *glyphs, int *nglyphs, QFontEngine::ShaperFlags flags) const +bool QFontEngineBox::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QFontEngine::ShaperFlags flags) const { if (*nglyphs < len) { *nglyphs = len; return false; } - memset(glyphs->glyphs, 0, len * sizeof(glyph_t)); + int ucs4Length = 0; + for (int i = 0; i < len; ++i) { + if (str[i].isHighSurrogate() && i + 1 < len && str[i + 1].isLowSurrogate()) + ++ucs4Length; + ++ucs4Length; + } + + memset(glyphs->glyphs, 0, ucs4Length * sizeof(glyph_t)); - *nglyphs = len; - glyphs->numGlyphs = len; + *nglyphs = ucs4Length; + glyphs->numGlyphs = ucs4Length; if (!(flags & GlyphIndicesOnly)) recalcAdvances(glyphs, flags); -- cgit v1.2.3