Fix possibly corrupted log clusters when using custom tab stops
The calculateTabWidth() can trigger shaping of the item, which can cause the layout data to be reallocated, so we need to update the local pointers to it, like we do when we explicitly invoke the shaper. [ChangeLog][Text] Fixed problems with text layout when using custom tab stops. Task-number: QTBUG-43126 Change-Id: Ifaeeeb4bfb1a55e6638b12b444f53d2679d3d1e6 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>bb10
parent
21101d9c52
commit
19bb9aa9e5
|
|
@ -1776,6 +1776,11 @@ void QTextLine::layout_helper(int maxGlyphs)
|
|||
|
||||
QFixed x = line.x + line.textWidth + lbh.tmpData.textWidth + lbh.spaceData.textWidth;
|
||||
QFixed tabWidth = eng->calculateTabWidth(item, x);
|
||||
attributes = eng->attributes();
|
||||
if (!attributes)
|
||||
return;
|
||||
lbh.logClusters = eng->layoutData->logClustersPtr;
|
||||
lbh.glyphs = eng->shapedGlyphs(¤t);
|
||||
|
||||
lbh.spaceData.textWidth += tabWidth;
|
||||
lbh.spaceData.length++;
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ private slots:
|
|||
void boundingRectForSetLineWidth();
|
||||
void glyphLessItems();
|
||||
void justifyTrailingSpaces();
|
||||
void layoutWithCustomTabStops();
|
||||
|
||||
// QTextLine stuff
|
||||
void setNumColumnsWrapAtWordBoundaryOrAnywhere();
|
||||
|
|
@ -2050,5 +2051,38 @@ void tst_QTextLayout::nbsp()
|
|||
layout.endLayout();
|
||||
}
|
||||
|
||||
void tst_QTextLayout::layoutWithCustomTabStops()
|
||||
{
|
||||
QScopedPointer<QTextLayout> textLayout(new QTextLayout);
|
||||
QList<QTextOption::Tab> tabStops;
|
||||
|
||||
const int tabWidth = 18;
|
||||
const int maxTabPos = 2500;
|
||||
for (int tabPos = tabWidth; tabPos < maxTabPos; tabPos += tabWidth)
|
||||
tabStops << QTextOption::Tab(tabPos, QTextOption::LeftTab);
|
||||
|
||||
QTextOption textOption;
|
||||
textOption.setTabs(tabStops);
|
||||
textLayout->setTextOption(textOption);
|
||||
|
||||
textLayout->setText(QStringLiteral("\ta aa aa aa aa aa aa"));
|
||||
|
||||
textLayout->beginLayout();
|
||||
textLayout->createLine();
|
||||
textLayout->endLayout();
|
||||
|
||||
qreal shortWidth = textLayout->maximumWidth();
|
||||
|
||||
textLayout->setText(QStringLiteral("\ta aa aa aa aa aa aa aa aa aa aa aa aa a"));
|
||||
|
||||
textLayout->beginLayout();
|
||||
textLayout->createLine();
|
||||
textLayout->endLayout();
|
||||
|
||||
qreal longWidth = textLayout->maximumWidth();
|
||||
|
||||
QVERIFY(longWidth > shortWidth);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QTextLayout)
|
||||
#include "tst_qtextlayout.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue