From dfa7774c4c2de3905a6df0fb57ef605fe91caba4 Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Thu, 3 Nov 2022 00:23:31 +0100 Subject: [PATCH] Non-windows: Link fontawesome into executable. (#442) --- src/imgui/imgui_extension.cpp | 21 ++++++++++++++------- src/resource/CMakeLists.txt | 10 ++++++++++ src/resource/embedded/fontawesome.S | 8 ++++++++ src/resource/embedded/fontawesome_macos.S | 8 ++++++++ 4 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 src/resource/embedded/fontawesome.S create mode 100644 src/resource/embedded/fontawesome_macos.S diff --git a/src/imgui/imgui_extension.cpp b/src/imgui/imgui_extension.cpp index 87d47c48..15e0de82 100644 --- a/src/imgui/imgui_extension.cpp +++ b/src/imgui/imgui_extension.cpp @@ -43,6 +43,10 @@ void ImRotateEnd(float rad, ImVec2 center) uint8* extractCafeDefaultFont(sint32* size); sint32 g_font_size = 0; uint8* g_font_data = nullptr; +#if !BOOST_OS_WINDOWS +extern int const g_fontawesome_size; +extern char const g_fontawesome_data[]; +#endif std::unordered_map g_imgui_fonts; std::stack g_font_requests; @@ -66,6 +70,14 @@ void ImGui_PrecacheFonts() //cfg.SizePixels = size; ImFont* font = io.Fonts->AddFontFromMemoryTTF(g_font_data, g_font_size, (float)size, &cfg); + ImFontConfig cfgmerge{}; + cfgmerge.FontDataOwnedByAtlas = false; + cfgmerge.MergeMode = true; + cfgmerge.GlyphMinAdvanceX = 20.0f; + //cfgmerge.GlyphOffset = { 2,2 }; + + static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; + #if BOOST_OS_WINDOWS const auto hinstance = GetModuleHandle(nullptr); const HRSRC res = FindResource(hinstance, MAKEINTRESOURCE(IDR_FONTAWESOME), RT_RCDATA); @@ -77,16 +89,11 @@ void ImGui_PrecacheFonts() void* data = LockResource(mem); const size_t len = SizeofResource(hinstance, res); - ImFontConfig cfgmerge{}; - cfgmerge.FontDataOwnedByAtlas = false; - cfgmerge.MergeMode = true; - cfgmerge.GlyphMinAdvanceX = 20.0f; - //cfgmerge.GlyphOffset = { 2,2 }; - - static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; io.Fonts->AddFontFromMemoryTTF(data, (int)len, (float)size, &cfgmerge, icon_ranges); } } +#else + io.Fonts->AddFontFromMemoryTTF((void*)g_fontawesome_data, (int)g_fontawesome_size, (float)size, &cfgmerge, icon_ranges); #endif g_imgui_fonts[(int)size] = font; diff --git a/src/resource/CMakeLists.txt b/src/resource/CMakeLists.txt index 23296998..78d7c6db 100644 --- a/src/resource/CMakeLists.txt +++ b/src/resource/CMakeLists.txt @@ -2,12 +2,22 @@ add_library(CemuResource) set_property(TARGET CemuResource PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +enable_language(ASM) + # icon resources target_sources(CemuResource PRIVATE embedded/resources.cpp embedded/resources.h ) +if(UNIX) + if(NOT APPLE) + target_sources(CemuResource PRIVATE embedded/fontawesome.S) + else() + target_sources(CemuResource PRIVATE embedded/fontawesome_macos.S) + endif() +endif() + target_sources(CemuResource PRIVATE CafeDefaultFont.cpp) target_include_directories(CemuResource PUBLIC "../") diff --git a/src/resource/embedded/fontawesome.S b/src/resource/embedded/fontawesome.S new file mode 100644 index 00000000..04da3b24 --- /dev/null +++ b/src/resource/embedded/fontawesome.S @@ -0,0 +1,8 @@ +.section .text +.global g_fontawesome_data, g_fontawesome_size + +g_fontawesome_data: +.incbin "fontawesome-webfont.ttf" +g_fontawesome_size: +.int g_fontawesome_size - g_fontawesome_data + diff --git a/src/resource/embedded/fontawesome_macos.S b/src/resource/embedded/fontawesome_macos.S new file mode 100644 index 00000000..3faeda9f --- /dev/null +++ b/src/resource/embedded/fontawesome_macos.S @@ -0,0 +1,8 @@ +.section __DATA, __const +.global _g_fontawesome_data, _g_fontawesome_size + +_g_fontawesome_data: +.incbin "fontawesome-webfont.ttf" +_g_fontawesome_size: +.int _g_fontawesome_size - _g_fontawesome_data +