*/
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();
*/
bool QGlyphRun::isEmpty() const
{
- return d->glyphIndexes.isEmpty();
+ return d->glyphIndexDataSize == 0;
}
QT_END_NAMESPACE
void assignment();
void equalsOperator_data();
void equalsOperator();
+ void isEmpty();
void textLayoutGlyphIndexes();
void drawExistingGlyphs();
void drawNonExistentGlyphs();
void detach();
void setRawData();
void setRawDataAndGetAsVector();
+ void boundingRect();
private:
int m_testFontId;
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()
{
}
+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)