summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-10-15 15:11:41 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-10-18 13:05:42 +0200
commit5335cc4a5a73bbd6d717989b4257660b92000fb6 (patch)
tree52b65fdf32b46832a5126dd589ace6c647fc1f20 /tests
parentf54044d4a92ab5ef04c11bc3ca9f064e91d97e63 (diff)
Fix cursor positioning on bidi boundaries
When the cursor is positioned between to script items that have different writing directions, prioritise the script item that has the same direction as the paragraph (i.e. the QTextEngine) when deciding where and how to display the cursor. If visual cursor movement is enabled, the behavior is unchanged. As a drive-by, clean up coding style and avoid shadowing of function- local variables. Task-number: QTBUG-88529 Pick-to: 6.2 Change-Id: I15227b10b1469d9caf1235b00e4d6f9f64a8b510 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
index a4c848c1ec..32a0374fcd 100644
--- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
+++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
@@ -74,6 +74,8 @@ private slots:
void cursorToXForTrailingSpaces_data();
void cursorToXForTrailingSpaces();
void cursorToXInvalidInput();
+ void cursorToXForBidiBoundaries_data();
+ void cursorToXForBidiBoundaries();
void horizontalAlignment_data();
void horizontalAlignment();
@@ -738,6 +740,58 @@ void tst_QTextLayout::cursorToXInvalidInput()
QCOMPARE(cursorPos, 3);
}
+void tst_QTextLayout::cursorToXForBidiBoundaries_data()
+{
+ QTest::addColumn<Qt::LayoutDirection>("textDirection");
+ QTest::addColumn<QString>("text");
+ QTest::addColumn<int>("cursorPosition");
+ QTest::addColumn<int>("expectedX");
+
+ QTest::addRow("LTR, abcشزذabc, 0") << Qt::LeftToRight << "abcشزذabc"
+ << 0 << 0;
+ QTest::addRow("RTL, abcشزذabc, 9") << Qt::RightToLeft << "abcشزذabc"
+ << 9 << TESTFONT_SIZE * 3;
+ QTest::addRow("LTR, abcشزذabc, 3") << Qt::LeftToRight << "abcشزذabc"
+ << 0 << 0;
+ QTest::addRow("RTL, abcشزذabc, 6") << Qt::RightToLeft << "abcشزذabc"
+ << 9 << TESTFONT_SIZE * 3;
+
+ QTest::addRow("LTR, شزذabcشزذ, 0") << Qt::LeftToRight << "شزذabcشزذ"
+ << 0 << TESTFONT_SIZE * 2;
+ QTest::addRow("RTL, شزذabcشزذ, 9") << Qt::RightToLeft << "شزذabcشزذ"
+ << 9 << 0;
+ QTest::addRow("LTR, شزذabcشزذ, 3") << Qt::LeftToRight << "شزذabcشزذ"
+ << 3 << TESTFONT_SIZE * 2;
+ QTest::addRow("RTL, شزذabcشزذ, 3") << Qt::RightToLeft << "شزذabcشزذ"
+ << 3 << TESTFONT_SIZE * 5;
+ QTest::addRow("LTR, شزذabcشزذ, 6") << Qt::LeftToRight << "شزذabcشزذ"
+ << 6 << TESTFONT_SIZE * 5;
+ QTest::addRow("RTL, شزذabcشزذ, 6") << Qt::RightToLeft << "شزذabcشزذ"
+ << 6 << TESTFONT_SIZE * 2;
+}
+
+void tst_QTextLayout::cursorToXForBidiBoundaries()
+{
+ QFETCH(Qt::LayoutDirection, textDirection);
+ QFETCH(QString, text);
+ QFETCH(int, cursorPosition);
+ QFETCH(int, expectedX);
+
+ QTextOption option;
+ option.setTextDirection(textDirection);
+
+ QTextLayout layout(text, testFont);
+ layout.setTextOption(option);
+ layout.beginLayout();
+
+ QTextLine line = layout.createLine();
+ line.setLineWidth(0x10000);
+
+ QCOMPARE(line.cursorToX(cursorPosition), expectedX);
+
+ layout.endLayout();
+}
+
void tst_QTextLayout::horizontalAlignment_data()
{
qreal width = TESTFONT_SIZE * 4;
@@ -1146,6 +1200,10 @@ void tst_QTextLayout::xToCursorForBidiEnds_data()
<< 0 << 6;
QTest::addRow("RTL, شزذabc") << Qt::RightToLeft << "شزذabc"
<< 6 << 0;
+ QTest::addRow("LTR, شزذ123") << Qt::LeftToRight << "شزذ123"
+ << 0 << 6;
+ QTest::addRow("RTL, شزذ123") << Qt::RightToLeft << "شزذ123"
+ << 6 << 0;
QTest::addRow("LTR, abcشزذabc") << Qt::LeftToRight << "abcشزذabc"
<< 0 << 9;