test: Fix test for oblique/italic equivalence

The tst_QFont::italicOblique() test is testing whether
a request for an "Oblique" font in the presence of an italic
one (or vice versa) may return the other as a second-best match.

However, it did not consider the fact that some fonts may not
be marked as italic even if the style name contains the word
"italic". One instance of this are variable fonts with oblique
instances. In this case we currently do not correctly recognize
the fonts as oblique.

But there is nothing preventing someone from creating a normal
font that has "italic" in the style name and not setting it as
italic in the OS/2 table (maybe the style name is "non-italic"),
so we can't really depend on this.

This makes the test a bit more robust by checking if the actual
font stored in the database is italic and verifying a match with
the requested oblique font. There are still cases that might
fail here, but we don't need to address those unless they
actually appear.

Pick-to: 6.5
Fixes: QTBUG-131108
Task-number: QTBUG-131262
Change-Id: I9ae0d37d378e8fec2be524db203dcea9a881f15a
Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 957e2be00a5c45223a5ef842a5f9f2f7b7be882b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2024-11-14 09:08:09 +01:00 committed by Qt Cherry-pick Bot
parent c73cc95ba7
commit 93f32fd47a

View File

@ -150,6 +150,9 @@ void tst_QFont::italicOblique()
QString style = *s_it;
if (QFontDatabase::isSmoothlyScalable(family, style)) {
QFont f = QFontDatabase::font(family, style, 12);
bool wasItalic = f.italic();
if (style.contains("Oblique")) {
style.replace("Oblique", "Italic");
} else if (style.contains("Italic")) {
@ -157,8 +160,8 @@ void tst_QFont::italicOblique()
} else {
continue;
}
QFont f = QFontDatabase::font(family, style, 12);
QVERIFY2(f.italic(), qPrintable(QString::asprintf("Failed for font \"%ls\"", qUtf16Printable(f.family()))));
f = QFontDatabase::font(family, style, 12);
QVERIFY2(f.italic() == wasItalic, qPrintable(QString::asprintf("Failed for font \"%ls\"", qUtf16Printable(f.family()))));
}
}
}