Fix QTextDocumentLayout test with certain fonts

If there is a negative right bearing on the last character of the string,
it will stretch past the tab position (which aligns the advance position,
and not the right edge of the glyph). For certain fonts, this would cause
the actual ideal width to be calculated as 301 instead of 300 (which is
the right alignment edge set in the code).

Pick-to: 5.15
Fixes: QTBUG-46206
Change-Id: I03e8b8fb86e9ebe5337d3ba3384ade73d2ccdd69
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2020-04-29 07:40:25 +02:00
parent 7a18b7e2c2
commit 8231614661

View File

@ -305,7 +305,9 @@ void tst_QTextDocumentLayout::imageAtRightAlignedTab()
#ifdef Q_OS_WINRT
QEXPECT_FAIL("", "Fails on winrt. Figure out why - QTBUG-68297", Continue);
#endif
QCOMPARE(doc->idealWidth(), 300.0);
qreal bearing = QFontMetricsF(doc->defaultFont()).rightBearing(QLatin1Char('t'));
QCOMPARE(doc->idealWidth(), std::max(300.0, 300.0 - bearing));
}
void tst_QTextDocumentLayout::blockVisibility()