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
parent
d443eff5b6
commit
d270bd8673
|
|
@ -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++)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue