diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2009-09-09 15:38:57 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2009-09-09 15:44:35 (GMT) |
commit | 07880542ecc479807c23c5646d263135240822ff (patch) | |
tree | 3e82442f58390ebc8ac71ab738749ca269037b43 /tests/auto/qfontmetrics/tst_qfontmetrics.cpp | |
parent | 80ca4cd1d9d9a1b725fb7a6016f1035c3d3ffc92 (diff) | |
download | Qt-07880542ecc479807c23c5646d263135240822ff.zip Qt-07880542ecc479807c23c5646d263135240822ff.tar.gz Qt-07880542ecc479807c23c5646d263135240822ff.tar.bz2 |
Account for right bearing in QFontMetrics::boundingRect(string)
QFontMetrics::boundingRect() that takes a string needs to account for
the right bearing of the last glyph, as it is documented to be the
rectangle that contains the pixels of the text. I've added a test for
this, and fixed tst_QFontMetrics::elidedText() to use boundingRect() to
find the actual width of the text drawn (width() will return the advance
of the text, which is larger than the actual width of the pixels.)
I've also fixed a small typo in the "len" -> "ilen".
Reviewed-by: Simon Hausmann
Diffstat (limited to 'tests/auto/qfontmetrics/tst_qfontmetrics.cpp')
-rw-r--r-- | tests/auto/qfontmetrics/tst_qfontmetrics.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/auto/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/qfontmetrics/tst_qfontmetrics.cpp index ee6d442..665107a 100644 --- a/tests/auto/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/qfontmetrics/tst_qfontmetrics.cpp @@ -72,6 +72,7 @@ private slots: void veryNarrowElidedText(); void averageCharWidth(); void elidedMultiLength(); + void bearingIncludedInBoundingRect(); }; tst_QFontMetrics::tst_QFontMetrics() @@ -214,7 +215,7 @@ void tst_QFontMetrics::elidedMultiLength() QCOMPARE(fm.elidedText(text1,Qt::ElideRight, 8000), text1_long); QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_long + 1), text1_long); QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_long - 1), text1_short); - int width_short = fm.width(text1_short); + int width_short = fm.boundingRect(text1_short).width(); QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_short + 1), text1_short); QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_short - 1), text1_small); @@ -226,5 +227,16 @@ void tst_QFontMetrics::elidedMultiLength() } +void tst_QFontMetrics::bearingIncludedInBoundingRect() +{ + QFont font; + font.setItalic(true); + QRect brectItalic = QFontMetrics(font).boundingRect("ITALIC"); + font.setItalic(false); + QRect brectNormal = QFontMetrics(font).boundingRect("ITALIC"); + + QVERIFY(brectItalic.width() > brectNormal.width()); +} + QTEST_MAIN(tst_QFontMetrics) #include "tst_qfontmetrics.moc" |