Fix bounding rect of glyph runs in multi-line QTextLayout
When getting the glyph runs from a QTextLayout with multiple lines, the glyph runs would be merged if possible, but not their bounding rects. This was an oversight. [ChangeLog][Text][QTextLayout] QTextLayout::glyphRuns() now returns united bounding rects for glyph runs that are merged. Change-Id: Ibbeaa99ecfc4e82e7965342efdae7c3c2b637343 Task-number: QTBUG-50715 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
parent
09e8d69b7a
commit
dce530b64e
@ -1058,12 +1058,15 @@ QList<QGlyphRun> QTextLayout::glyphRuns(int from, int length) const
|
||||
|
||||
QVector<quint32> indexes = oldGlyphRun.glyphIndexes();
|
||||
QVector<QPointF> positions = oldGlyphRun.positions();
|
||||
QRectF boundingRect = oldGlyphRun.boundingRect();
|
||||
|
||||
indexes += glyphRun.glyphIndexes();
|
||||
positions += glyphRun.positions();
|
||||
boundingRect = boundingRect.united(glyphRun.boundingRect());
|
||||
|
||||
oldGlyphRun.setGlyphIndexes(indexes);
|
||||
oldGlyphRun.setPositions(positions);
|
||||
oldGlyphRun.setBoundingRect(boundingRect);
|
||||
} else {
|
||||
glyphRunHash[key] = glyphRun;
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ private slots:
|
||||
void setRawDataAndGetAsVector();
|
||||
void boundingRect();
|
||||
void mixedScripts();
|
||||
void multiLineBoundingRect();
|
||||
|
||||
private:
|
||||
int m_testFontId;
|
||||
@ -735,6 +736,34 @@ void tst_QGlyphRun::mixedScripts()
|
||||
QCOMPARE(glyphRuns.size(), 2);
|
||||
}
|
||||
|
||||
void tst_QGlyphRun::multiLineBoundingRect()
|
||||
{
|
||||
QTextLayout layout;
|
||||
layout.setText("Foo Bar");
|
||||
layout.beginLayout();
|
||||
|
||||
QTextLine line = layout.createLine();
|
||||
line.setNumColumns(4);
|
||||
line.setPosition(QPointF(0, 0));
|
||||
|
||||
line = layout.createLine();
|
||||
line.setPosition(QPointF(0, 10));
|
||||
|
||||
layout.endLayout();
|
||||
|
||||
QCOMPARE(layout.lineCount(), 2);
|
||||
|
||||
QList<QGlyphRun> firstLineGlyphRuns = layout.lineAt(0).glyphRuns();
|
||||
QList<QGlyphRun> allGlyphRuns = layout.glyphRuns();
|
||||
QCOMPARE(firstLineGlyphRuns.size(), 1);
|
||||
QCOMPARE(allGlyphRuns.size(), 1);
|
||||
|
||||
QGlyphRun firstLineGlyphRun = firstLineGlyphRuns.first();
|
||||
QGlyphRun allGlyphRun = allGlyphRuns.first();
|
||||
|
||||
QVERIFY(firstLineGlyphRun.boundingRect().height() < allGlyphRun.boundingRect().height());
|
||||
}
|
||||
|
||||
#endif // QT_NO_RAWFONT
|
||||
|
||||
QTEST_MAIN(tst_QGlyphRun)
|
||||
|
Loading…
Reference in New Issue
Block a user