Don't alter input string in QTextLayout with ShowLineAndParagraphSeparators

When ShowLineAndParagraphSeparators was set, we would replace the
separator character in the user's string in some cases, since we never
detached from the input string and just const_cast the pointer to the
shared buffer.

[ChangeLog][QtGui][Text] Fixed bug where a QTextLayout with
ShowLineAndParagraphSeparators would modify the layout's input
string.

Task-number: QTBUG-42033
Change-Id: I92f9100b750f16e52b38b718245c13e5c4a0ebb9
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2016-05-31 10:56:25 +02:00
parent 58408ffa1b
commit 8fb29ed259
2 changed files with 40 additions and 1 deletions
src/gui/text
tests/auto/gui/text/qtextlayout

View File

@ -1635,8 +1635,14 @@ void QTextEngine::itemize() const
if (analysis->bidiLevel % 2)
--analysis->bidiLevel;
analysis->flags = QScriptAnalysis::LineOrParagraphSeparator;
if (option.flags() & QTextOption::ShowLineAndParagraphSeparators)
if (option.flags() & QTextOption::ShowLineAndParagraphSeparators) {
const int offset = uc - string;
layoutData->string.detach();
string = reinterpret_cast<const ushort *>(layoutData->string.unicode());
uc = string + offset;
e = uc + length;
*const_cast<ushort*>(uc) = 0x21B5; // visual line separator
}
break;
case QChar::Tabulation:
analysis->flags = QScriptAnalysis::Tab;

View File

@ -142,6 +142,7 @@ private slots:
void xToCursorForLigatures();
void cursorInNonStopChars();
void nbsp();
void noModificationOfInputString();
private:
QFont testFont;
@ -2176,5 +2177,37 @@ void tst_QTextLayout::layoutWithCustomTabStops()
QVERIFY(longWidth > shortWidth);
}
void tst_QTextLayout::noModificationOfInputString()
{
QString s = QString(QChar(QChar::LineSeparator));
{
QTextLayout layout;
layout.setText(s);
layout.beginLayout();
layout.createLine();
layout.endLayout();
QCOMPARE(s.size(), 1);
QCOMPARE(s.at(0), QChar(QChar::LineSeparator));
}
{
QTextLayout layout;
layout.setText(s);
QTextOption option;
option.setFlags(QTextOption::ShowLineAndParagraphSeparators);
layout.setTextOption(option);
layout.beginLayout();
layout.createLine();
layout.endLayout();
QCOMPARE(s.size(), 1);
QCOMPARE(s.at(0), QChar(QChar::LineSeparator));
}
}
QTEST_MAIN(tst_QTextLayout)
#include "tst_qtextlayout.moc"