From ec4593d6d06b6b6de5cd26cf66d5c6a866231251 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Thu, 11 Oct 2012 06:23:32 +0300 Subject: [PATCH] QGlyphRun: Fix isEmpty() and boundingRect() didn't work after setRawData() Change-Id: I44a347ef24961493d6b8353abbb215c713ccce52 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qglyphrun.cpp | 10 +++--- tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp | 46 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/gui/text/qglyphrun.cpp b/src/gui/text/qglyphrun.cpp index 48e0b15..f46e86e 100644 --- a/src/gui/text/qglyphrun.cpp +++ b/src/gui/text/qglyphrun.cpp @@ -473,15 +473,15 @@ void QGlyphRun::setBoundingRect(const QRectF &boundingRect) */ QRectF QGlyphRun::boundingRect() const { - if (!d->boundingRect.isEmpty()) + if (!d->boundingRect.isEmpty() || !d->rawFont.isValid()) return d->boundingRect; qreal minX, minY, maxX, maxY; minX = minY = maxX = maxY = 0; - for (int i=0; iglyphPositions.size(), d->glyphIndexes.size()); ++i) { - QRectF glyphRect = d->rawFont.boundingRect(d->glyphIndexes.at(i)); - glyphRect.translate(d->glyphPositions.at(i)); + for (int i = 0, n = qMin(d->glyphIndexDataSize, d->glyphPositionDataSize); i < n; ++i) { + QRectF glyphRect = d->rawFont.boundingRect(d->glyphIndexData[i]); + glyphRect.translate(d->glyphPositionData[i]); if (i == 0) { minX = glyphRect.left(); @@ -506,7 +506,7 @@ QRectF QGlyphRun::boundingRect() const */ bool QGlyphRun::isEmpty() const { - return d->glyphIndexes.isEmpty(); + return d->glyphIndexDataSize == 0; } QT_END_NAMESPACE diff --git a/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp b/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp index d982428..0245594 100644 --- a/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp +++ b/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp @@ -63,6 +63,7 @@ private slots: void assignment(); void equalsOperator_data(); void equalsOperator(); + void isEmpty(); void textLayoutGlyphIndexes(); void drawExistingGlyphs(); void drawNonExistentGlyphs(); @@ -75,6 +76,7 @@ private slots: void detach(); void setRawData(); void setRawDataAndGetAsVector(); + void boundingRect(); private: int m_testFontId; @@ -235,6 +237,22 @@ void tst_QGlyphRun::equalsOperator() QCOMPARE(one != two, !equals); } +void tst_QGlyphRun::isEmpty() +{ + QGlyphRun glyphs; + QVERIFY(glyphs.isEmpty()); + + glyphs.setGlyphIndexes(QVector() << 1 << 2 << 3); + QVERIFY(!glyphs.isEmpty()); + + glyphs.clear(); + QVERIFY(glyphs.isEmpty()); + + QVector glyphIndexes = QVector() << 1 << 2 << 3; + QVector positions = QVector() << QPointF(0, 0) << QPointF(0, 0) << QPointF(0, 0); + glyphs.setRawData(glyphIndexes.constData(), positions.constData(), glyphIndexes.size()); + QVERIFY(!glyphs.isEmpty()); +} void tst_QGlyphRun::textLayoutGlyphIndexes() { @@ -675,6 +693,34 @@ void tst_QGlyphRun::drawRightToLeft() } +void tst_QGlyphRun::boundingRect() +{ + QString s(QLatin1String("AbCdE")); + + QRawFont rawFont(QRawFont::fromFont(QFont())); + QVERIFY(rawFont.isValid()); + QVector glyphIndexes = rawFont.glyphIndexesForString(s); + QVector positions = rawFont.advancesForGlyphIndexes(glyphIndexes); + QCOMPARE(glyphIndexes.size(), s.size()); + QCOMPARE(positions.size(), glyphIndexes.size()); + + QGlyphRun glyphs; + glyphs.setRawFont(rawFont); + glyphs.setGlyphIndexes(glyphIndexes); + glyphs.setPositions(positions); + + QRectF boundingRect = glyphs.boundingRect(); + + glyphs.clear(); + glyphs.setRawFont(rawFont); + glyphs.setRawData(glyphIndexes.constData(), positions.constData(), glyphIndexes.size()); + QCOMPARE(glyphs.boundingRect(), boundingRect); + + boundingRect = QRectF(0, 0, 1, 1); + glyphs.setBoundingRect(boundingRect); + QCOMPARE(glyphs.boundingRect(), boundingRect); +} + #endif // QT_NO_RAWFONT QTEST_MAIN(tst_QGlyphRun) -- 2.7.4