Skip to content

Commit

Permalink
QFontIconEngine: if we can't find the named glyph, try ligatures
Browse files Browse the repository at this point in the history
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.

Pick-to: 6.9
Change-Id: If0e5c528c3ac4cccdbb7df5fb7fd32ca232f2a66
Reviewed-by: Eskil Abrahamsen Blomfeldt <[email protected]>
  • Loading branch information
vohi committed Dec 11, 2024
1 parent 9d47233 commit d10e917
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/gui/image/qfonticonengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QtGui/qpainter.h>
#include <QtGui/qpainterpath.h>
#include <QtGui/qpalette.h>
#include <QtGui/qtextlayout.h>

#include <QtGui/private/qfont_p.h>
#include <QtGui/private/qfontengine_p.h>
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d10e917

Please sign in to comment.