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.7 6.5 6.2
Fixes: QTBUG-127512
Change-Id: Id3ae7a6c79c84edd603db2fc0fed07777fa67741
Reviewed-by: Liang Qi <liang.qi@qt.io>
(cherry picked from commit e7ac6667f27369c25719ebedefd2d5344fd93bfd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2024-08-06 07:45:46 +02:00 committed by Qt Cherry-pick Bot
parent a758315eba
commit 5f5dafac08

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);