QTextBlock: Handle surrogates in textDirection()
authorKonstantin Ritt <ritt.ks@gmail.com>
Sun, 14 Oct 2012 22:37:03 +0000 (01:37 +0300)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 16 Oct 2012 00:47:51 +0000 (02:47 +0200)
just like QString does.

Change-Id: I002827d9ec93fb19ef2c0198b5fcd4dae15c5c34
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
src/gui/text/qtextobject.cpp

index abe1035..349f886 100644 (file)
@@ -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: