Skip to content

Commit

Permalink
Refactor: only include Noto Color Font where usable (on Linux only)
Browse files Browse the repository at this point in the history
Only on that OS does it provide the Colour Emojis characters we want, on
Windows and MacOs the system forces the use of their proprietary font and
FreeBSD does not seem to provide color font support...

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
  • Loading branch information
SlySven committed Mar 25, 2020
1 parent 1b44455 commit 33f2961
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 14 deletions.
11 changes: 9 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
############################################################################
# Copyright (C) 2014-2017 by Ahmed Charles - acharles@outlook.com #
# Copyright (C) 2015-2018 by Stephen Lyons - slysven@virginmedia.com #
# Copyright (C) 2015-2018, 2020 by Stephen Lyons #
# - slysven@virginmedia.com #
# Copyright (C) 2018 by Huadong Qi - novload@outlook.com #
# #
# This program is free software; you can redistribute it and/or modify #
Expand All @@ -22,7 +23,13 @@
set(mudlet_RCCS mudlet.qrc)

if(USE_FONTS)
list(APPEND mudlet_RCCS mudlet_fonts.qrc)
list(APPEND mudlet_RCCS mudlet_fonts_common.qrc)
# There is not an equivalent to WIN32 for Linux specifically instead we must
# check the value of CMAKE_SYSTEM_NAME - see:
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Write-Platform-Checks:
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
list(APPEND mudlet_RCCS mudlet_fonts_linux.qrc)
endif()
endif()

if(WIN32)
Expand Down
1 change: 1 addition & 0 deletions src/TConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "pre_guard.h"
#include <QLineEdit>
#include <QMessageBox>
#include <QMimeData>
#include <QRegularExpression>
#include <QScrollBar>
#include <QShortcut>
Expand Down
5 changes: 4 additions & 1 deletion src/TLuaInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3338,8 +3338,11 @@ int TLuaInterpreter::setFont(lua_State* L)
font = QString::fromUtf8(lua_tostring(L, s));
}

// ensure that emojis are displayed in colour even if this font doesn't support it
#if defined(Q_OS_LINUX)
// On Linux ensure that emojis are displayed in colour even if this font
// doesn't support it:
QFont::insertSubstitution(font, QStringLiteral("Noto Color Emoji"));
#endif

if (windowName.isEmpty() || windowName.compare(QStringLiteral("main"), Qt::CaseSensitive) == 0) {
if (mudlet::self()->mConsoleMap.contains(pHost)) {
Expand Down
6 changes: 5 additions & 1 deletion src/XMLimport.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2016-2019 by Stephen Lyons - slysven@virginmedia.com *
* Copyright (C) 2016-2020 by Stephen Lyons - slysven@virginmedia.com *
* Copyright (C) 2016-2017 by Ian Adkins - ieadkins@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down Expand Up @@ -1032,7 +1032,11 @@ void XMLimport::readHostPackage(Host* pHost)
pHost->mLightWhite.setNamedColor(readElementText());
} else if (name() == "mDisplayFont") {
pHost->setDisplayFontFromString(readElementText());
#if defined(Q_OS_LINUX)
// On Linux ensure that emojis are displayed in colour even if
// this font doesn't support it:
QFont::insertSubstitution(pHost->mDisplayFont.family(), QStringLiteral("Noto Color Emoji"));
#endif
pHost->setDisplayFontFixedPitch(true);
} else if (name() == "mCommandLineFont") {
pHost->mCommandLineFont.fromString(readElementText());
Expand Down
7 changes: 6 additions & 1 deletion src/dlgProfilePreferences.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************************************************************
* Copyright (C) 2008-2012 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2014, 2016-2018 by Stephen Lyons *
* Copyright (C) 2014, 2016-2018, 2020 by Stephen Lyons *
* - slysven@virginmedia.com *
* Copyright (C) 2016 by Ian Adkins - ieadkins@gmail.com *
* *
Expand Down Expand Up @@ -1623,7 +1623,12 @@ void dlgProfilePreferences::setDisplayFont()
label_variableWidthFontWarning->show();
}

#if defined(Q_OS_LINUX)
// On Linux ensure that emojis are displayed in colour even if this font
// doesn't support it:
QFont::insertSubstitution(pHost->mDisplayFont.family(), QStringLiteral("Noto Color Emoji"));
#endif

auto* mainConsole = mudlet::self()->mConsoleMap.value(pHost);
if (!mainConsole) {
return;
Expand Down
10 changes: 8 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2013-2014, 2016-2019 by Stephen Lyons *
* Copyright (C) 2013-2014, 2016-2020 by Stephen Lyons *
* - slysven@virginmedia.com *
* Copyright (C) 2014-2017 by Ahmed Charles - acharles@outlook.com *
* *
Expand Down Expand Up @@ -380,10 +380,13 @@ int main(int argc, char* argv[])
if (!dir.exists(ubuntuFontDirectory)) {
dir.mkpath(ubuntuFontDirectory);
}
#if defined(Q_OS_LINUX)
// Only needed/works on Linux to provide color emojis:
QString notoFontDirectory(QStringLiteral("%1/notocoloremoji-unhinted-2018-04-24-pistol-update").arg(mudlet::getMudletPath(mudlet::mainFontsPath)));
if (!dir.exists(notoFontDirectory)) {
dir.mkpath(notoFontDirectory);
}
#endif

// The original code plonks the fonts AND the Copyright into the MAIN mudlet
// directory - but the Copyright statement is specifically for the fonts
Expand Down Expand Up @@ -433,9 +436,12 @@ int main(int argc, char* argv[])
copyFont(ubuntuFontDirectory, QLatin1String("fonts/ubuntu-font-family-0.83"), QLatin1String("UbuntuMono-R.ttf"));
copyFont(ubuntuFontDirectory, QLatin1String("fonts/ubuntu-font-family-0.83"), QLatin1String("UbuntuMono-RI.ttf"));

#if defined(Q_OS_LINUX)
copyFont(notoFontDirectory, QStringLiteral("fonts/notocoloremoji-unhinted-2018-04-24-pistol-update"), QStringLiteral("NotoColorEmoji.ttf"));
copyFont(notoFontDirectory, QStringLiteral("fonts/notocoloremoji-unhinted-2018-04-24-pistol-update"), QStringLiteral("LICENSE_OFL.txt"));
#endif
copyFont(notoFontDirectory, QStringLiteral("fonts/notocoloremoji-unhinted-2018-04-24-pistol-update"), QStringLiteral("README"));
#endif // defined(Q_OS_LINUX)
#endif // defined(INCLUDE_FONTS)

mudlet::debugMode = false;

Expand Down
16 changes: 12 additions & 4 deletions src/mudlet.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
############################################################################
# Copyright (C) 2013-2015, 2017-2018 by Stephen Lyons #
# Copyright (C) 2013-2015, 2017-2018, 2020 by Stephen Lyons #
# - slysven@virginmedia.com #
# Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com #
# Copyright (C) 2017 by Ian Adkins - ieadkins@gmail.com #
Expand Down Expand Up @@ -623,11 +623,19 @@ FORMS += \
ui/trigger_pattern_edit.ui \
ui/vars_main_area.ui

RESOURCES = mudlet.qrc \
../translations/translated/qm.qrc
RESOURCES += \
mudlet.qrc \
../translations/translated/qm.qrc

contains(DEFINES, INCLUDE_FONTS) {
RESOURCES += mudlet_fonts.qrc
RESOURCES += \
mudlet_fonts_common.qrc

linux {
RESOURCES += \
mudlet_fonts_linux.qrc
}

!build_pass{
# On windows or on platforms that support CONFIG having debug_and_release"
# then there can be three passes through this file and we only want the
Expand Down
3 changes: 0 additions & 3 deletions src/mudlet_fonts.qrc → src/mudlet_fonts_common.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,5 @@
<file>fonts/ubuntu-font-family-0.83/Ubuntu-MI.ttf</file>
<file>fonts/ubuntu-font-family-0.83/Ubuntu-R.ttf</file>
<file>fonts/ubuntu-font-family-0.83/Ubuntu-RI.ttf</file>
<file>fonts/notocoloremoji-unhinted-2018-04-24-pistol-update/LICENSE_OFL.txt</file>
<file>fonts/notocoloremoji-unhinted-2018-04-24-pistol-update/NotoColorEmoji.ttf</file>
<file>fonts/notocoloremoji-unhinted-2018-04-24-pistol-update/README</file>
</qresource>
</RCC>
7 changes: 7 additions & 0 deletions src/mudlet_fonts_linux.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/">
<file>fonts/notocoloremoji-unhinted-2018-04-24-pistol-update/LICENSE_OFL.txt</file>
<file>fonts/notocoloremoji-unhinted-2018-04-24-pistol-update/NotoColorEmoji.ttf</file>
<file>fonts/notocoloremoji-unhinted-2018-04-24-pistol-update/README</file>
</qresource>
</RCC>

0 comments on commit 33f2961

Please sign in to comment.