diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2018-12-20 09:27:09 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2018-12-21 10:27:12 +0000 |
commit | e6880e7cd145fe07651e8afdfd4a15d57b810024 (patch) | |
tree | 22ea4d5ed49824416f9afef9e1cf1351a9e70c9e /tests | |
parent | b45c1e1c0e3dd838543c1e8d4725d9436367a16a (diff) | |
download | qtbase-e6880e7cd145fe07651e8afdfd4a15d57b810024.tar.gz |
Fix text shifting vertically when elided
When eliding text we would check for the existence of the ellipsis
character and fall back to using the dot if it was not available.
However, when font merging was in use, we would also use ellipsis
from a fallback font if available. This could cause the metrics
of the text to increase if the fallback font had larger metrics,
and the result was that text could shift when elided.
It is better to prefer the dot from the current font than to use
the ellipsis from a fallback, so we only use the ellipsis if
it is in the main font.
[ChangeLog][QtGui][Text] Fixed a bug where eliding text could
change the height of its bounding rectangle for certain fonts.
Fixes: QTBUG-72553
Change-Id: Ib27fc65302465ddce661801bcc5ae32e55f1aeb9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/text/qfontmetrics/testfont.qrc | 1 | ||||
-rw-r--r-- | tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qfontmetrics/testfont.qrc b/tests/auto/gui/text/qfontmetrics/testfont.qrc index bc0c0b0959..30b4a3f82e 100644 --- a/tests/auto/gui/text/qfontmetrics/testfont.qrc +++ b/tests/auto/gui/text/qfontmetrics/testfont.qrc @@ -1,5 +1,6 @@ <RCC> <qresource prefix="/fonts"> <file>ucs4font.ttf</file> + <file alias="testfont.ttf">../../../shared/resources/testfont.ttf</file> </qresource> </RCC> diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index 9e705b4a00..a0e8525268 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -58,6 +58,7 @@ private slots: void lineWidth(); void mnemonicTextWidth(); void leadingBelowLine(); + void elidedMetrics(); }; void tst_QFontMetrics::same() @@ -331,5 +332,31 @@ void tst_QFontMetrics::leadingBelowLine() QCOMPARE(line.base(), line.ascent); } +void tst_QFontMetrics::elidedMetrics() +{ + QString testFont = QFINDTESTDATA("fonts/testfont.ttf"); + QVERIFY(!testFont.isEmpty()); + + int id = QFontDatabase::addApplicationFont(testFont); + QVERIFY(id >= 0); + + QFont font(QFontDatabase::applicationFontFamilies(id).at(0)); + font.setPixelSize(12.0); + + QFontMetricsF metrics(font); + QString s = QStringLiteral("VeryLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongText"); + + QRectF boundingRect = metrics.boundingRect(s); + + QString elided = metrics.elidedText(s, Qt::ElideRight, boundingRect.width() / 2.0); + + QRectF elidedBoundingRect = metrics.boundingRect(elided); + + QCOMPARE(boundingRect.height(), elidedBoundingRect.height()); + QCOMPARE(boundingRect.y(), elidedBoundingRect.y()); + + QFontDatabase::removeApplicationFont(id); +} + QTEST_MAIN(tst_QFontMetrics) #include "tst_qfontmetrics.moc" |