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:
parent
58408ffa1b
commit
8fb29ed259
@ -1635,8 +1635,14 @@ void QTextEngine::itemize() const
|
|||||||
if (analysis->bidiLevel % 2)
|
if (analysis->bidiLevel % 2)
|
||||||
--analysis->bidiLevel;
|
--analysis->bidiLevel;
|
||||||
analysis->flags = QScriptAnalysis::LineOrParagraphSeparator;
|
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
|
*const_cast<ushort*>(uc) = 0x21B5; // visual line separator
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case QChar::Tabulation:
|
case QChar::Tabulation:
|
||||||
analysis->flags = QScriptAnalysis::Tab;
|
analysis->flags = QScriptAnalysis::Tab;
|
||||||
|
@ -142,6 +142,7 @@ private slots:
|
|||||||
void xToCursorForLigatures();
|
void xToCursorForLigatures();
|
||||||
void cursorInNonStopChars();
|
void cursorInNonStopChars();
|
||||||
void nbsp();
|
void nbsp();
|
||||||
|
void noModificationOfInputString();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFont testFont;
|
QFont testFont;
|
||||||
@ -2176,5 +2177,37 @@ void tst_QTextLayout::layoutWithCustomTabStops()
|
|||||||
QVERIFY(longWidth > shortWidth);
|
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)
|
QTEST_MAIN(tst_QTextLayout)
|
||||||
#include "tst_qtextlayout.moc"
|
#include "tst_qtextlayout.moc"
|
||||||
|
Loading…
Reference in New Issue
Block a user