QTextEngine: fix layouting of inline objects in right-aligned tabs.

(same thing for center- and delimiter-aligned tabs)

The width of the inline object wasn't taken into account, the code in
QTextEngine::calculateTabWidth only looked at glyph widths.

Change-Id: I303a6561c67870ff2094a685698e642fc1b53b12
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
bb10
David Faure 2013-11-18 18:52:26 +01:00 committed by The Qt Project
parent d443eff5b6
commit d270bd8673
2 changed files with 40 additions and 0 deletions

View File

@ -2878,6 +2878,10 @@ QFixed QTextEngine::calculateTabWidth(int item, QFixed x) const
if (item.position > tabSectionEnd || item.position <= si.position)
continue;
shape(i); // first, lets make sure relevant text is already shaped
if (item.analysis.flags == QScriptAnalysis::Object) {
length += item.width;
continue;
}
QGlyphLayout glyphs = this->shapedGlyphs(&item);
const int end = qMin(item.position + item.num_glyphs, tabSectionEnd) - item.position;
for (int i=0; i < end; i++)

View File

@ -74,6 +74,7 @@ private slots:
void inlineImage();
void clippedTableCell();
void floatingTablePageBreak();
void imageAtRightAlignedTab();
private:
QTextDocument *doc;
@ -283,6 +284,41 @@ void tst_QTextDocumentLayout::floatingTablePageBreak()
QCOMPARE(doc->pageCount(), 2);
}
void tst_QTextDocumentLayout::imageAtRightAlignedTab()
{
doc->clear();
QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
fmt.setMargin(0);
doc->rootFrame()->setFrameFormat(fmt);
QTextCursor cursor(doc);
QTextBlockFormat blockFormat;
QList<QTextOption::Tab> tabs;
QTextOption::Tab tab;
tab.position = 300;
tab.type = QTextOption::RightTab;
tabs.append(tab);
blockFormat.setTabPositions(tabs);
// First block: text, some of it right-aligned
cursor.insertBlock(blockFormat);
cursor.insertText("first line\t");
cursor.insertText("right-aligned text");
// Second block: text, then right-aligned image
cursor.insertBlock(blockFormat);
cursor.insertText("second line\t");
QImage img(48, 48, QImage::Format_RGB32);
const QString name = QString::fromLatin1("image");
doc->addResource(QTextDocument::ImageResource, QUrl(name), img);
QTextImageFormat imgFormat;
imgFormat.setName(name);
cursor.insertImage(imgFormat);
// Everything should fit into the 300 pixels
QCOMPARE(doc->idealWidth(), 300.0);
}
QTEST_MAIN(tst_QTextDocumentLayout)
#include "tst_qtextdocumentlayout.moc"