From 3de6c570fb5e7988be12535e01dca262b997e9b9 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 4 Dec 2024 21:53:45 +0100 Subject: [PATCH] QFontIconEngine: if we can't find the named glyph, try ligatures Use QTextLayout to layout and shape the text, which will respect ligatures. Many icon fonts might not name their icons, but have a replacement ligature for the actual icon name replacing the text with the respective glyph. So if for the name of the icon we get a single glyph run with a single glyph in it, use that to render the icon. Change-Id: If0e5c528c3ac4cccdbb7df5fb7fd32ca232f2a66 Reviewed-by: Eskil Abrahamsen Blomfeldt (cherry picked from commit d10e9174fecb91b5c366d57aeb19e6410522a807) Reviewed-by: Qt Cherry-pick Bot --- src/gui/image/qfonticonengine.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/gui/image/qfonticonengine.cpp b/src/gui/image/qfonticonengine.cpp index e98fa1bffdd..c02fba7f0c5 100644 --- a/src/gui/image/qfonticonengine.cpp +++ b/src/gui/image/qfonticonengine.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -167,6 +168,20 @@ glyph_t QFontIconEngine::glyph() const QFontEngine *engine = QFontPrivate::get(m_iconFont)->engineForScript(QChar::Script_Common); if (engine) m_glyph = engine->findGlyph(QLatin1StringView(m_iconName.toLatin1())); + if (!m_glyph) { + // May not be a named glyph, but there might be a ligature for the + // icon name. + QTextLayout layout(m_iconName, m_iconFont); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + const auto glyphRuns = layout.glyphRuns(); + if (glyphRuns.size() == 1) { + const auto glyphIndexes = glyphRuns.first().glyphIndexes(); + if (glyphIndexes.size() == 1) + m_glyph = glyphIndexes.first(); + } + } } return m_glyph; }