From d270bd8673505d8325ce25fa8476c8f8bc5a075b Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 18 Nov 2013 18:52:26 +0100 Subject: 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 Reviewed-by: Allan Sandfeld Jensen --- src/gui/text/qtextengine.cpp | 4 +++ .../tst_qtextdocumentlayout.cpp | 36 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 6345ed7682..08b0491ddc 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -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++) diff --git a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp index 2d122125e0..3c5ba884f7 100644 --- a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp +++ b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp @@ -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 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" -- cgit v1.2.3