void tst_QComplexText::bidiReorderString() { QFETCH( QString, logical ); QFETCH( int, basicDir ); // replace \n with Unicode newline. The new algorithm ignores \n logical.replace(QChar('\n'), QChar(0x2028)); QTextEngine e(logical, QFont()); e.option.setTextDirection((QChar::Direction)basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft); e.itemize(); quint8 levels[256]; int visualOrder[256]; int nitems = e.layoutData->items.size(); int i; for (i = 0; i < nitems; ++i) { //qDebug("item %d bidiLevel=%d", i, e.items[i].analysis.bidiLevel); levels[i] = e.layoutData->items[i].analysis.bidiLevel; } e.bidiReorder(nitems, levels, visualOrder); QString visual; for (i = 0; i < nitems; ++i) { QScriptItem &si = e.layoutData->items[visualOrder[i]]; QString sub = logical.mid(si.position, e.length(visualOrder[i])); if (si.analysis.bidiLevel % 2) { // reverse sub QChar *a = (QChar *)sub.unicode(); QChar *b = a + sub.length() - 1; while (a < b) { QChar tmp = *a; *a = *b; *b = tmp; ++a; --b; } a = (QChar *)sub.unicode(); b = a + sub.length(); while (a<b) { *a = a->mirroredChar(); ++a; } } visual += sub; } // replace Unicode newline back with \n to compare. visual.replace(QChar(0x2028), QChar('\n')); QTEST(visual, "VISUAL"); }