diff --git a/3rdparty/imgui/include/imconfig.h b/3rdparty/imgui/include/imconfig.h index fd4f1753df..e58ea4afa8 100644 --- a/3rdparty/imgui/include/imconfig.h +++ b/3rdparty/imgui/include/imconfig.h @@ -66,7 +66,7 @@ //#define IMGUI_USE_LEGACY_CRC32_ADLER //---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) -//#define IMGUI_USE_WCHAR32 +#define IMGUI_USE_WCHAR32 //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. diff --git a/bin/resources/fonts/NotoColorEmoji-Regular-license b/bin/resources/fonts/NotoColorEmoji-Regular-license new file mode 100644 index 0000000000..04e112f225 --- /dev/null +++ b/bin/resources/fonts/NotoColorEmoji-Regular-license @@ -0,0 +1,93 @@ +Copyright 2021 Google Inc. All Rights Reserved. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/bin/resources/fonts/NotoColorEmoji-Regular.ttf b/bin/resources/fonts/NotoColorEmoji-Regular.ttf new file mode 100644 index 0000000000..9851173f4e Binary files /dev/null and b/bin/resources/fonts/NotoColorEmoji-Regular.ttf differ diff --git a/cmake/SearchForStuff.cmake b/cmake/SearchForStuff.cmake index 78f62d3346..91c83a2ad7 100644 --- a/cmake/SearchForStuff.cmake +++ b/cmake/SearchForStuff.cmake @@ -18,7 +18,7 @@ find_package(Zstd 1.5.5 REQUIRED) find_package(LZ4 REQUIRED) find_package(WebP REQUIRED) # v1.3.2, spews an error on Linux because no pkg-config. find_package(SDL3 3.2.6 REQUIRED) -find_package(Freetype 2.11.1 REQUIRED) +find_package(Freetype 2.12 REQUIRED) find_package(plutovg 1.1.0 REQUIRED) find_package(plutosvg 0.0.7 REQUIRED) diff --git a/pcsx2/ImGui/ImGuiManager.cpp b/pcsx2/ImGui/ImGuiManager.cpp index 3b81450b57..46c73a2ead 100644 --- a/pcsx2/ImGui/ImGuiManager.cpp +++ b/pcsx2/ImGui/ImGuiManager.cpp @@ -25,6 +25,7 @@ #include "fmt/format.h" #include "imgui.h" +#include "imgui_freetype.h" #include "imgui_internal.h" #include "common/Image.h" @@ -56,6 +57,7 @@ namespace ImGuiManager static ImFont* AddTextFont(); static ImFont* AddFixedFont(); static bool AddIconFonts(); + static bool AddEmojiFont(); static void AcquirePendingOSDMessages(Common::Timer::Value current_time); static void DrawOSDMessages(Common::Timer::Value current_time); static void CreateSoftwareCursorTextures(); @@ -74,6 +76,7 @@ static ImFont* s_fixed_font; static std::vector s_standard_font_data; static std::vector s_fixed_font_data; +static std::vector s_emoji_font_data; static std::vector s_icon_fa_font_data; static std::vector s_icon_pf_font_data; @@ -415,6 +418,16 @@ bool ImGuiManager::LoadFontData() s_fixed_font_data = std::move(font_data.value()); } + if (s_emoji_font_data.empty()) + { + std::optional> font_data = FileSystem::ReadBinaryFile( + EmuFolders::GetOverridableResourcePath("fonts" FS_OSPATH_SEPARATOR_STR "NotoColorEmoji-Regular.ttf").c_str()); + if (!font_data.has_value()) + return false; + + s_emoji_font_data = std::move(font_data.value()); + } + if (s_icon_fa_font_data.empty()) { std::optional> font_data = @@ -442,6 +455,7 @@ void ImGuiManager::UnloadFontData() { std::vector().swap(s_standard_font_data); std::vector().swap(s_fixed_font_data); + std::vector().swap(s_emoji_font_data); std::vector().swap(s_icon_fa_font_data); std::vector().swap(s_icon_pf_font_data); } @@ -475,11 +489,15 @@ bool ImGuiManager::AddIconFonts() { // Load FontAwesome after to avoid aliased codepoints overriding promptfont { + // Exclude emojis + static constexpr ImWchar range_exclude_emojis[] = {0x10000, 0x1ffff, 0x0, 0x0}; + ImFontConfig cfg; cfg.MergeMode = true; cfg.PixelSnapH = true; cfg.GlyphMinAdvanceX = FONT_BASE_SIZE; cfg.GlyphMaxAdvanceX = FONT_BASE_SIZE; + cfg.GlyphExcludeRanges = range_exclude_emojis; cfg.FontDataOwnedByAtlas = false; if (!ImGui::GetIO().Fonts->AddFontFromMemoryTTF( @@ -491,7 +509,7 @@ bool ImGuiManager::AddIconFonts() { // Exclude any characters outside the BMP PUA plane - static constexpr ImWchar range_exclude_non_bmp[] = {0x1, 0xdfff, 0xf900, 0xffff, 0x0, 0x0}; + static constexpr ImWchar range_exclude_non_bmp[] = {0x1, 0xdfff, 0xf900, 0x10ffff, 0x0, 0x0}; ImFontConfig cfg; cfg.MergeMode = true; @@ -511,17 +529,75 @@ bool ImGuiManager::AddIconFonts() return true; } +bool ImGuiManager::AddEmojiFont() +{ + { + // ImGui can't correctly handle some Unicode codepoints + // Remove them to avoid rendering blank/fallback characters + // See https://github.com/ocornut/imgui/issues/8240 + static ImFontLoader filter_loader; + filter_loader.Name = "Emoji Preprocessor"; + filter_loader.FontSrcContainsGlyph = [](ImFontAtlas* atlas, ImFontConfig* src, ImWchar codepoint) { + if (codepoint == 0xfe0e || codepoint == 0xfe0f) + return true; + return false; + }; + filter_loader.FontBakedLoadGlyph = [](ImFontAtlas* atlas, ImFontConfig* src, ImFontBaked* baked, void*, ImWchar codepoint, ImFontGlyph* out_glyph, float* out_advance_x) { + if (codepoint != 0xfe0e && codepoint != 0xfe0f) + return false; + + // Metrics only mode + if (out_advance_x != nullptr) + { + *out_advance_x = 0.0f; + return true; + } + + out_glyph->Codepoint = codepoint; + out_glyph->AdvanceX = 0.0f; + out_glyph->Visible = false; + + return true; + }; + + ImFontConfig cfg; + StringUtil::Strlcpy(cfg.Name, filter_loader.Name, sizeof(cfg.Name)); + cfg.MergeMode = true; + cfg.SizePixels = FONT_BASE_SIZE; + cfg.FontLoader = &filter_loader; + if (!ImGui::GetIO().Fonts->AddFont(&cfg)) + return false; + } + + { + ImFontConfig cfg; + cfg.MergeMode = true; + // Set GlyphMin/MaxAdvanceX to allow replacing FA/PF icons. + cfg.GlyphMinAdvanceX = FONT_BASE_SIZE; + cfg.GlyphMaxAdvanceX = FONT_BASE_SIZE; + cfg.FontLoaderFlags |= ImGuiFreeTypeLoaderFlags_LoadColor; + cfg.FontDataOwnedByAtlas = false; + + if (!ImGui::GetIO().Fonts->AddFontFromMemoryTTF( + s_emoji_font_data.data(), static_cast(s_emoji_font_data.size()), FONT_BASE_SIZE, &cfg, nullptr)) + { + return false; + } + } + return true; +} + bool ImGuiManager::AddImGuiFonts() { ImGuiIO& io = ImGui::GetIO(); io.Fonts->Clear(); s_standard_font = AddTextFont(); - if (!s_standard_font || !AddIconFonts()) + if (!s_standard_font || !AddIconFonts() || !AddEmojiFont()) return false; s_fixed_font = AddFixedFont(); - if (!s_fixed_font) + if (!s_fixed_font || !AddEmojiFont()) return false; ImGuiFullscreen::SetFont(s_standard_font);