diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-10-12 12:52:39 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-10-21 12:37:22 +0200 |
commit | 4748369eb2e458e12f5228a113b9a6dda440b24b (patch) | |
tree | a89935b29f535aa15f1c2e9815fee2cd0b08fba8 /tests | |
parent | 6dd6342864806fcb28318da38a01ce21fcb4c96a (diff) |
Fix inconsistencies between advanceWidth and bounding rects
Unify the logic in QTextEngine
Ensure tightBoundingRect, and the FreeType boundingRect, calculates from
the shaped x offset when calculating the max x coordinate for a glyph.
Fixes: QTBUG-7768
Task-number: QTBUG-70184
Task-number: QTBUG-85936
Task-number: QTBUG-94023
Change-Id: I6daafb25c79158dc7e777529abb5e8d3a284dac0
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index c78475a76f..9ed88fe8ed 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -43,6 +43,7 @@ private slots: void same(); void metrics(); void boundingRect(); + void boundingRect2(); void elidedText_data(); void elidedText(); void veryNarrowElidedText(); @@ -149,6 +150,21 @@ void tst_QFontMetrics::boundingRect() QVERIFY(r.top() < 0); } +void tst_QFontMetrics::boundingRect2() +{ + QFont f; + f.setPixelSize(16); + QFontMetricsF fm(f); + QString str("AVAVAVA vvvvvvvvvv fffffffff file"); + QRectF br = fm.boundingRect(str); + QRectF tbr = fm.tightBoundingRect(str); + qreal advance = fm.horizontalAdvance(str); + // Bounding rect plus bearings should be similar to advance + qreal bearings = fm.leftBearing(QChar('A')) + fm.rightBearing(QChar('e')); + QVERIFY(qAbs(br.width() + bearings - advance) < fm.averageCharWidth()/2.0); + QVERIFY(qAbs(tbr.width() + bearings - advance) < fm.averageCharWidth()/2.0); +} + void tst_QFontMetrics::elidedText_data() { QTest::addColumn<QFont>("font"); @@ -374,6 +390,8 @@ void tst_QFontMetrics::zeroWidthMetrics() QCOMPARE(fm.horizontalAdvance(string3), fm.horizontalAdvance(string4)); QCOMPARE(fm.boundingRect(string1).width(), fm.boundingRect(string2).width()); QCOMPARE(fm.boundingRect(string3).width(), fm.boundingRect(string4).width()); + QCOMPARE(fm.tightBoundingRect(string1).width(), fm.tightBoundingRect(string2).width()); + QCOMPARE(fm.tightBoundingRect(string3).width(), fm.tightBoundingRect(string4).width()); } QTEST_MAIN(tst_QFontMetrics) |