Don't count no-break spaces as trailing spaces

No-break-spaces should not be counted in the space data, but rather
be treated as any other non-breakable character. We were already
taking care of this in the loop we reach if the item starts with
a character which isn't whitespace, but there is a second loop for
items that begin with whitespace characters.

The result of this was that in certain circumstances where you gave
the nbsp its own format and made the line wrap, the previous line
would count an extra trailing space and it would swallow the first
character in its following line.

[ChangeLog][QtGui][Text] Fixed a bug where a no-break space would
sometimes cause the first character of the containing line to not be
displayed.

Task-number: QTBUG-56714
Change-Id: Idd760a389052e6de70f6cc397122b217987fa5f2
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2016-11-04 15:52:32 +01:00
parent 8ee65cd1f2
commit 15414257b3
2 changed files with 43 additions and 2 deletions

View File

@ -1896,11 +1896,15 @@ void QTextLine::layout_helper(int maxGlyphs)
++lbh.glyphCount;
if (lbh.checkFullOtherwiseExtend(line))
goto found;
} else if (attributes[lbh.currentPosition].whiteSpace) {
} else if (attributes[lbh.currentPosition].whiteSpace
&& eng->layoutData->string.at(lbh.currentPosition).decompositionTag() != QChar::NoBreak) {
lbh.whiteSpaceOrObject = true;
while (lbh.currentPosition < end && attributes[lbh.currentPosition].whiteSpace)
while (lbh.currentPosition < end
&& attributes[lbh.currentPosition].whiteSpace
&& eng->layoutData->string.at(lbh.currentPosition).decompositionTag() != QChar::NoBreak) {
addNextCluster(lbh.currentPosition, end, lbh.spaceData, lbh.glyphCount,
current, lbh.logClusters, lbh.glyphs);
}
if (!lbh.manualWrap && lbh.spaceData.textWidth > line.width) {
lbh.spaceData.textWidth = line.width; // ignore spaces that fall out of the line.

View File

@ -142,6 +142,7 @@ private slots:
void xToCursorForLigatures();
void cursorInNonStopChars();
void nbsp();
void nbspWithFormat();
void noModificationOfInputString();
void superscriptCrash_qtbug53911();
@ -2266,5 +2267,41 @@ void tst_QTextLayout::superscriptCrash_qtbug53911()
qDeleteAll(textLayouts);
}
void tst_QTextLayout::nbspWithFormat()
{
QString s1 = QLatin1String("ABCDEF ");
QString s2 = QLatin1String("GHI");
QChar nbsp(QChar::Nbsp);
QString s3 = QLatin1String("JKLMNOPQRSTUVWXYZ");
QTextLayout layout;
layout.setText(s1 + s2 + nbsp + s3);
QTextLayout::FormatRange formatRange;
formatRange.start = s1.length() + s2.length();
formatRange.length = 1;
formatRange.format.setFontUnderline(true);
QList<QTextLayout::FormatRange> overrides;
overrides.append(formatRange);
layout.setAdditionalFormats(overrides);
layout.beginLayout();
forever {
QTextLine line = layout.createLine();
if (!line.isValid())
break;
line.setLineWidth(1);
}
layout.endLayout();
QCOMPARE(layout.lineCount(), 2);
QCOMPARE(layout.lineAt(0).textStart(), 0);
QCOMPARE(layout.lineAt(0).textLength(), s1.length());
QCOMPARE(layout.lineAt(1).textStart(), s1.length());
QCOMPARE(layout.lineAt(1).textLength(), s2.length() + 1 + s3.length());
}
QTEST_MAIN(tst_QTextLayout)
#include "tst_qtextlayout.moc"