From 25677ec4b2957f7fd56618781dec28cb139f9df7 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 25 Feb 2020 15:59:31 +0100 Subject: Fix bounding box of zero-width entities in QFontEngineFT Freetype can give us non empty bounds for zero-width characters, this change just makes us skip metrics of characters already found to not contribute to text advance. The coretext and windows font-engines already uses the already calculated advance. Change-Id: I82b3521a4fb92614be509be5982cd5ab9c1eb7de Fixes: QTBUG-58854 Reviewed-by: Konstantin Ritt Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../gui/text/qfontmetrics/tst_qfontmetrics.cpp | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index a0e8525268..6fe3e20083 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -59,6 +59,7 @@ private slots: void mnemonicTextWidth(); void leadingBelowLine(); void elidedMetrics(); + void zeroWidthMetrics(); }; void tst_QFontMetrics::same() @@ -358,5 +359,28 @@ void tst_QFontMetrics::elidedMetrics() QFontDatabase::removeApplicationFont(id); } +void tst_QFontMetrics::zeroWidthMetrics() +{ + QString zwnj(QChar(0x200c)); + QString zwsp(QChar(0x200b)); + + QFont font; + QFontMetricsF fm(font); + QCOMPARE(fm.horizontalAdvance(zwnj), 0); + QCOMPARE(fm.horizontalAdvance(zwsp), 0); + QCOMPARE(fm.boundingRect(zwnj).width(), 0); + QCOMPARE(fm.boundingRect(zwsp).width(), 0); + + QString string1 = QStringLiteral("(") + zwnj + QStringLiteral(")"); + QString string2 = QStringLiteral("(") + zwnj + zwnj + QStringLiteral(")"); + QString string3 = QStringLiteral("(") + zwsp + QStringLiteral(")"); + QString string4 = QStringLiteral("(") + zwsp + zwsp + QStringLiteral(")"); + + QCOMPARE(fm.horizontalAdvance(string1), fm.horizontalAdvance(string2)); + 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()); +} + QTEST_MAIN(tst_QFontMetrics) #include "tst_qfontmetrics.moc" -- cgit v1.2.3