Skip to content

Commit

Permalink
Fix: Use Apple Emoji on MacOS (Mudlet#7452)
Browse files Browse the repository at this point in the history
#### Brief overview of PR changes/additions
Mudlet built with Qt5 on MacOS doesn't correctly fall back to using
Apple Color Emoji for either user-selected or default system fonts.
This change adds Apple Color Emoji to the font family of both the
user-selected font and the default system fonts, allowing for correct
emoji display. This is especially visible with compound emoji that use
ZWJ.

As far as I can tell, this issue is greatly improved or non-existent in
Qt6 on MacOS, so I've put these changes behind a QT_VERSION_CHECK for
that reason.

#### Motivation for adding to Mudlet
I would like emoji to render nicely on the Mac. 


#### Other info (issues closed, discussion etc)

Co-authored-by: Vadim Peretokin <[email protected]>
  • Loading branch information
rparet and vadi2 authored Oct 8, 2024
1 parent 3bda2f7 commit 0fecda7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/TLuaInterpreterUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,11 @@ int TLuaInterpreter::setFont(lua_State* L)
// TODO issue #4159: a nonexisting font breaks the console
#endif

#if defined(Q_OS_MACOS) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// Add Apple Color Emoji fallback.
QFont::insertSubstitution(font, qsl("Apple Color Emoji"));
#endif

auto console = CONSOLE(L, windowName);
if (console == host.mpConsole) {
// apply changes to main console and its while-scrolling component too.
Expand Down
4 changes: 4 additions & 0 deletions src/XMLimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,10 @@ void XMLimport::readHost(Host* pHost)
// On Linux ensure that emojis are displayed in colour even if
// this font doesn't support it:
QFont::insertSubstitution(pHost->mDisplayFont.family(), qsl("Noto Color Emoji"));
#endif
#if defined(Q_OS_MACOS) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// Add Apple Color Emoji fallback.
QFont::insertSubstitution(pHost->mDisplayFont.family(), qsl("Apple Color Emoji"));
#endif
pHost->setDisplayFontFixedPitch(true);
} else if (name() == qsl("mCommandLineFont")) {
Expand Down
5 changes: 5 additions & 0 deletions src/dlgProfilePreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,11 @@ void dlgProfilePreferences::slot_setDisplayFont()
QFont::insertSubstitution(pHost->mDisplayFont.family(), qsl("Noto Color Emoji"));
#endif

#if defined(Q_OS_MACOS) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// Add Apple Color Emoji fallback.
QFont::insertSubstitution(pHost->mDisplayFont.family(), qsl("Apple Color Emoji"));
#endif

auto mainConsole = pHost->mpConsole;
if (!mainConsole) {
return;
Expand Down
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ int main(int argc, char* argv[])
QAccessible::installFactory(Announcer::accessibleFactory);
#endif

#if defined(Q_OS_MACOS) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// Apple Color Emoji Fallback
QFont defaultFont;
defaultFont.setFamily(defaultFont.defaultFamily());
QFont::insertSubstitution(defaultFont.family(), qsl("Apple Color Emoji"));
app->setFont(defaultFont);
#endif

#if defined(Q_OS_WIN32) && defined(INCLUDE_UPDATER)
auto abortLaunch = runUpdate();
if (abortLaunch) {
Expand Down
4 changes: 4 additions & 0 deletions src/mudlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ void mudlet::init()
}

const QFont mainFont = QFont(qsl("Bitstream Vera Sans Mono"), 8, QFont::Normal);
#if defined(Q_OS_MACOS) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// Add Apple Color Emoji fallback.
QFont::insertSubstitution(mainFont.family(), qsl("Apple Color Emoji"));
#endif
mpWidget_profileContainer->setFont(mainFont);
mpWidget_profileContainer->show();

Expand Down

0 comments on commit 0fecda7

Please sign in to comment.