QGlyphRun: Fix isEmpty() and boundingRect() didn't work after setRawData()
authorKonstantin Ritt <ritt.ks@gmail.com>
Thu, 11 Oct 2012 03:23:32 +0000 (06:23 +0300)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sat, 13 Oct 2012 01:17:53 +0000 (03:17 +0200)
Change-Id: I44a347ef24961493d6b8353abbb215c713ccce52
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
src/gui/text/qglyphrun.cpp
tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp

index 48e0b15..f46e86e 100644 (file)
@@ -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; i<qMin(d->glyphPositions.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
index d982428..0245594 100644 (file)
@@ -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<quint32>() << 1 << 2 << 3);
+    QVERIFY(!glyphs.isEmpty());
+
+    glyphs.clear();
+    QVERIFY(glyphs.isEmpty());
+
+    QVector<quint32> glyphIndexes = QVector<quint32>() << 1 << 2 << 3;
+    QVector<QPointF> positions = QVector<QPointF>() << 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<quint32> glyphIndexes = rawFont.glyphIndexesForString(s);
+    QVector<QPointF> 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)