QFontIconEngine: always initialize with a non-merging font

The icon engine needs to be able to rely on glyph indices belonging to
the correct font, and we generally don't want the overhead of iterating
through potential fallbacks if a named glyph or unicode code point
wasn't found in the font.

Assert in the QFontIconEngine constructor that the font we get has the
NoFontMerging strategy bit set.

Amends 2af58490b3d33aab8d08610939fe2b7cab4c469c.

Pick-to: 6.9
Change-Id: Ib38324aebbeda956c8dd053969d6cf08f7ef3c35
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
Volker Hilsheimer 2024-12-10 11:36:45 +01:00
parent a117525515
commit 9d47233d2c
3 changed files with 11 additions and 5 deletions

View File

@ -25,6 +25,8 @@ QFontIconEngine::QFontIconEngine(const QString &iconName, const QFont &font)
: m_iconName(iconName)
, m_iconFont(font)
{
Q_ASSERT_X(font.styleStrategy() & QFont::NoFontMerging, "QFontIconEngine",
"Icon fonts must not use font merging");
}
QFontIconEngine::~QFontIconEngine() = default;

View File

@ -249,7 +249,9 @@ static QFont selectFont()
// last resort - use any Material Icons
if (fontFamily.isEmpty())
fontFamily = u"Material Icons"_s;
return QFont(fontFamily);
QFont font(fontFamily);
font.setStyleStrategy(QFont::NoFontMerging);
return font;
}
} // namespace FontProvider

View File

@ -286,16 +286,18 @@ static QString getGlyphs(QStringView iconName)
}
namespace {
static auto iconFontFamily()
static auto iconFont()
{
static const bool isWindows11 = QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows11;
return isWindows11 ? u"Segoe Fluent Icons"_s
: u"Segoe MDL2 Assets"_s;
QFont font(isWindows11 ? u"Segoe Fluent Icons"_s
: u"Segoe MDL2 Assets"_s);
font.setStyleStrategy(QFont::NoFontMerging);
return font;
}
}
QWindowsIconEngine::QWindowsIconEngine(const QString &iconName)
: QFontIconEngine(iconName, iconFontFamily())
: QFontIconEngine(iconName, iconFont())
, m_glyphs(getGlyphs(iconName))
{
}