From 4bfea3634fa7d8d1d3b3469a9a7776a4015bc82a Mon Sep 17 00:00:00 2001 From: alef Date: Sat, 24 Aug 2024 12:38:05 +0200 Subject: [PATCH 1/5] Add typeface(s) to `load_fonts` --- src/cata_imgui.cpp | 5 +++-- src/cata_imgui.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index 578c9709730bb..0e53fa40a222d 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -255,8 +255,9 @@ static int GetFallbackCharWidth( ImWchar c, const float scale ) return fontwidth * mk_wcwidth( c ) * scale; } -void cataimgui::client::load_fonts( const std::unique_ptr &cata_font, - const std::array::COLOR_NAMES_COUNT> &windowsPalette ) +void cataimgui::client::load_fonts( const Font_Ptr &cata_font, + const std::array::COLOR_NAMES_COUNT> &windowsPalette, + const std::vector &typefaces) { ImGuiIO &io = ImGui::GetIO(); if( ImGui::GetIO().FontDefault == nullptr ) { diff --git a/src/cata_imgui.h b/src/cata_imgui.h index 3e23ef3af667c..706adf9cc2f86 100644 --- a/src/cata_imgui.h +++ b/src/cata_imgui.h @@ -60,8 +60,9 @@ class client #else client( const SDL_Renderer_Ptr &sdl_renderer, const SDL_Window_Ptr &sdl_window, const GeometryRenderer_Ptr &sdl_geometry ); - void load_fonts( const std::unique_ptr &cata_font, - const std::array::COLOR_NAMES_COUNT> &windowsPalette ); + void load_fonts( const std::unique_ptr &cata_fonts, + const std::array::COLOR_NAMES_COUNT> &windowsPalette, + const std::vector &typeface); #endif ~client(); From e86ac682a91a6f40eb50719c55361031eb9ba25c Mon Sep 17 00:00:00 2001 From: alef Date: Sat, 24 Aug 2024 12:39:07 +0200 Subject: [PATCH 2/5] Initialize local typefaces with given list --- src/cata_imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index 0e53fa40a222d..56486508a8891 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -261,7 +261,7 @@ void cataimgui::client::load_fonts( const Font_Ptr &cata_font, { ImGuiIO &io = ImGui::GetIO(); if( ImGui::GetIO().FontDefault == nullptr ) { - std::vector typefaces; + std::vector io_typefaces{ typefaces }; ensure_unifont_loaded( typefaces ); for( size_t index = 0; index < color_loader::COLOR_NAMES_COUNT; index++ ) { From 2936de5969f398f2770ba04b2106838ded735fda Mon Sep 17 00:00:00 2001 From: alef Date: Sat, 24 Aug 2024 12:39:42 +0200 Subject: [PATCH 3/5] Pass font loader typeface(s) --- src/sdltiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 44eb79bb479aa..27a1914920b11 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -3728,7 +3728,7 @@ void catacurses::init_interface() windowsPalette, fl.overmap_typeface, fl.overmap_fontsize, fl.fontblending ); stdscr = newwin( get_terminal_height(), get_terminal_width(), point_zero ); //newwin calls `new WINDOW`, and that will throw, but not return nullptr. - imclient->load_fonts( font, windowsPalette ); + imclient->load_fonts( font, windowsPalette, fl.typeface); #if defined(__ANDROID__) // Make sure we initialize preview_terminal_width/height to sensible values preview_terminal_width = TERMINAL_WIDTH * fontwidth; From 0abbaed3907e8f727985df7d3caf336a9d2d471d Mon Sep 17 00:00:00 2001 From: alef Date: Sat, 24 Aug 2024 12:40:09 +0200 Subject: [PATCH 4/5] Rename local variable --- src/cata_imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index 56486508a8891..be695cb80bac6 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -262,14 +262,14 @@ void cataimgui::client::load_fonts( const Font_Ptr &cata_font, ImGuiIO &io = ImGui::GetIO(); if( ImGui::GetIO().FontDefault == nullptr ) { std::vector io_typefaces{ typefaces }; - ensure_unifont_loaded( typefaces ); + ensure_unifont_loaded( io_typefaces ); for( size_t index = 0; index < color_loader::COLOR_NAMES_COUNT; index++ ) { SDL_Color sdlCol = windowsPalette[index]; ImU32 rgb = sdlCol.b << 16 | sdlCol.g << 8 | sdlCol.r; sdlColorsToCata[rgb] = index; } - io.FontDefault = io.Fonts->AddFontFromFileTTF( typefaces[0].c_str(), fontheight, nullptr, + io.FontDefault = io.Fonts->AddFontFromFileTTF( io_typefaces[0].c_str(), fontheight, nullptr, io.Fonts->GetGlyphRangesDefault() ); io.Fonts->Fonts[0]->SetFallbackStrSizeCallback( GetFallbackStrWidth ); io.Fonts->Fonts[0]->SetFallbackCharSizeCallback( GetFallbackCharWidth ); From 0615d557a9e21a62a858694b60529b728ce790ee Mon Sep 17 00:00:00 2001 From: alef Date: Sat, 24 Aug 2024 14:06:09 +0200 Subject: [PATCH 5/5] Obey astyle --- src/cata_imgui.cpp | 2 +- src/cata_imgui.h | 2 +- src/sdltiles.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index be695cb80bac6..6243488674d14 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -257,7 +257,7 @@ static int GetFallbackCharWidth( ImWchar c, const float scale ) void cataimgui::client::load_fonts( const Font_Ptr &cata_font, const std::array::COLOR_NAMES_COUNT> &windowsPalette, - const std::vector &typefaces) + const std::vector &typefaces ) { ImGuiIO &io = ImGui::GetIO(); if( ImGui::GetIO().FontDefault == nullptr ) { diff --git a/src/cata_imgui.h b/src/cata_imgui.h index 706adf9cc2f86..c927d0ade6bd5 100644 --- a/src/cata_imgui.h +++ b/src/cata_imgui.h @@ -62,7 +62,7 @@ class client const GeometryRenderer_Ptr &sdl_geometry ); void load_fonts( const std::unique_ptr &cata_fonts, const std::array::COLOR_NAMES_COUNT> &windowsPalette, - const std::vector &typeface); + const std::vector &typeface ); #endif ~client(); diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 27a1914920b11..ba782827c9ed9 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -3728,7 +3728,7 @@ void catacurses::init_interface() windowsPalette, fl.overmap_typeface, fl.overmap_fontsize, fl.fontblending ); stdscr = newwin( get_terminal_height(), get_terminal_width(), point_zero ); //newwin calls `new WINDOW`, and that will throw, but not return nullptr. - imclient->load_fonts( font, windowsPalette, fl.typeface); + imclient->load_fonts( font, windowsPalette, fl.typeface ); #if defined(__ANDROID__) // Make sure we initialize preview_terminal_width/height to sensible values preview_terminal_width = TERMINAL_WIDTH * fontwidth;