Do not put cursor at non-stop character positions
When moving cursors, non-stop positions are skipped, however certain input sequences can still lead us there. In such cases we should simply ignore those positions in cursorToX. Task-number: QTBUG-7076 Change-Id: Ia0a25931f4043359f72a6c0c14a74b905e40b93e Reviewed-by: Eskil Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
This commit is contained in:
parent
75a2b9eef2
commit
c30ebdeac0
@ -2549,6 +2549,9 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
|
|||||||
|
|
||||||
int pos = *cursorPos;
|
int pos = *cursorPos;
|
||||||
int itm;
|
int itm;
|
||||||
|
const HB_CharAttributes *attributes = eng->attributes();
|
||||||
|
while (pos < line.from + line.length && !attributes[pos].charStop)
|
||||||
|
pos++;
|
||||||
if (pos == line.from + (int)line.length) {
|
if (pos == line.from + (int)line.length) {
|
||||||
// end of line ensure we have the last item on the line
|
// end of line ensure we have the last item on the line
|
||||||
itm = eng->findItem(pos-1);
|
itm = eng->findItem(pos-1);
|
||||||
|
@ -139,6 +139,7 @@ private slots:
|
|||||||
void textWidthWithLineSeparator();
|
void textWidthWithLineSeparator();
|
||||||
void cursorInLigatureWithMultipleLines();
|
void cursorInLigatureWithMultipleLines();
|
||||||
void xToCursorForLigatures();
|
void xToCursorForLigatures();
|
||||||
|
void cursorInNonStopChars();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFont testFont;
|
QFont testFont;
|
||||||
@ -1472,7 +1473,7 @@ void tst_QTextLayout::textWidthWithLineSeparator()
|
|||||||
void tst_QTextLayout::cursorInLigatureWithMultipleLines()
|
void tst_QTextLayout::cursorInLigatureWithMultipleLines()
|
||||||
{
|
{
|
||||||
#if !defined(Q_WS_MAC)
|
#if !defined(Q_WS_MAC)
|
||||||
QSKIP("This test can not be run on Mac");
|
QSKIP("This test can only be run on Mac");
|
||||||
#endif
|
#endif
|
||||||
QTextLayout layout("first line finish", QFont("Times", 20));
|
QTextLayout layout("first line finish", QFont("Times", 20));
|
||||||
layout.beginLayout();
|
layout.beginLayout();
|
||||||
@ -1488,7 +1489,7 @@ void tst_QTextLayout::cursorInLigatureWithMultipleLines()
|
|||||||
void tst_QTextLayout::xToCursorForLigatures()
|
void tst_QTextLayout::xToCursorForLigatures()
|
||||||
{
|
{
|
||||||
#if !defined(Q_WS_MAC)
|
#if !defined(Q_WS_MAC)
|
||||||
QSKIP("This test can not be run on Mac");
|
QSKIP("This test can only be run on Mac");
|
||||||
#endif
|
#endif
|
||||||
QTextLayout layout("fi", QFont("Times", 20));
|
QTextLayout layout("fi", QFont("Times", 20));
|
||||||
layout.beginLayout();
|
layout.beginLayout();
|
||||||
@ -1509,5 +1510,19 @@ void tst_QTextLayout::xToCursorForLigatures()
|
|||||||
line.xToCursor(width) == line.xToCursor(width / 2));
|
line.xToCursor(width) == line.xToCursor(width / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QTextLayout::cursorInNonStopChars()
|
||||||
|
{
|
||||||
|
#if defined(Q_WS_MAC)
|
||||||
|
QSKIP("This test can not be run on Mac", SkipAll);
|
||||||
|
#endif
|
||||||
|
QTextLayout layout(QString::fromUtf8("\xE0\xA4\xA4\xE0\xA5\x8D\xE0\xA4\xA8"));
|
||||||
|
layout.beginLayout();
|
||||||
|
QTextLine line = layout.createLine();
|
||||||
|
layout.endLayout();
|
||||||
|
|
||||||
|
QVERIFY(line.cursorToX(1) == line.cursorToX(3));
|
||||||
|
QVERIFY(line.cursorToX(2) == line.cursorToX(3));
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QTextLayout)
|
QTEST_MAIN(tst_QTextLayout)
|
||||||
#include "tst_qtextlayout.moc"
|
#include "tst_qtextlayout.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user