QGlyphRun: Fix isEmpty() and boundingRect() didn't work after setRawData()
Change-Id: I44a347ef24961493d6b8353abbb215c713ccce52 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>bb10
parent
4717d36c91
commit
ec4593d6d0
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue