From 4e5d686a87c4e86aae42d1a5921eec22151f12a5 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 26 May 2020 08:11:06 +0200 Subject: Make tst_QTextLayout::textWidthVsWIdth() more robust Some fonts misreport the minimum right bearing, and in those cases we may not be able to do a perfect text layout inside the bounds set. This is a limitation we have chosen to accept. To avoid random failure when testing this, we detect the case and skip the test if we see that it may fail. Fixes: QTBUG-84415 Pick-to: 5.15 Change-Id: I6b53ea2631c5c6e476e2902b5514829a2141796f Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp') diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index 9c5b58884a..cb71f91a7a 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -2016,6 +2016,21 @@ void tst_QTextLayout::textWidthVsWIdth() // minimum right bearing reported by the font engine doesn't cover all the glyphs in the font. // The result is that this test may fail in some cases. We should fix this by running the test // with a font that we know have no suprising right bearings. See qtextlayout.cpp for details. + QFontMetricsF fontMetrics(layout.font()); + QSet checked; + qreal minimumRightBearing = 0.0; + for (int i = 0; i < layout.text().size(); ++i) { + QChar c = layout.text().at(i); + if (!checked.contains(c.unicode())) { + qreal rightBearing = fontMetrics.rightBearing(c); + if (rightBearing < minimumRightBearing) + minimumRightBearing = rightBearing; + checked.insert(c.unicode()); + } + } + if (minimumRightBearing < fontMetrics.minRightBearing()) + QSKIP("Font reports invalid minimum right bearing, and can't be used for this test."); + for (int width = 100; width < 1000; ++width) { layout.beginLayout(); QTextLine line = layout.createLine(); -- cgit v1.2.3