Fix tst_QTextLayout::softHyphens failure with some fonts

The test did not account for the fact that kerning can alter the
distance between subsequent characters, so sum of horizontal
advances does not accurately measure the width of the string when
kerning is enabled.

This caused the test to fail with e.g. with the font Ubuntu Sans.

This amends 0ffdbb21261eee3a9ec1cd541478ee883a12065c .

Pick-to: 6.2 6.5 6.7 6.8
Fixes: QTBUG-127512
Change-Id: Id3ae7a6c79c84edd603db2fc0fed07777fa67741
Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2024-08-06 07:45:46 +02:00 committed by Liang Qi
parent f48f425d3e
commit e7ac6667f2

View File

@ -2563,6 +2563,7 @@ void tst_QTextLayout::softHyphens()
QFont font;
font.setPixelSize(fontSize);
font.setHintingPreference(QFont::PreferNoHinting);
font.setKerning(false);
const float xAdvance = QFontMetricsF(font).horizontalAdvance(QChar::fromLatin1('x'));
float shyWidth = 0.0f;
QTextLayout layout(text, font);