From 46ed9dbaa0a3627513c1f89c46b5e67d1e1af14b Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Mon, 15 Oct 2012 01:37:03 +0300 Subject: [PATCH] QTextBlock: Handle surrogates in textDirection() just like QString does. Change-Id: I002827d9ec93fb19ef2c0198b5fcd4dae15c5c34 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qtextobject.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp index abe1035..349f886 100644 --- a/src/gui/text/qtextobject.cpp +++ b/src/gui/text/qtextobject.cpp @@ -1185,8 +1185,15 @@ Qt::LayoutDirection QTextBlock::textDirection() const const QChar *p = buffer.constData() + frag->stringPosition; const QChar * const end = p + frag->size_array[0]; while (p < end) { - switch(QChar::direction(p->unicode())) - { + uint ucs4 = p->unicode(); + if (QChar::isHighSurrogate(ucs4) && p + 1 < end) { + ushort low = p[1].unicode(); + if (QChar::isLowSurrogate(low)) { + ucs4 = QChar::surrogateToUcs4(ucs4, low); + ++p; + } + } + switch (QChar::direction(ucs4)) { case QChar::DirL: return Qt::LeftToRight; case QChar::DirR: -- 2.7.4