Skip to content

Commit

Permalink
Merge pull request #75920 from alef/73019-typefaces
Browse files Browse the repository at this point in the history
ImGui to respect `fonts.json`
  • Loading branch information
Maleclypse authored Aug 25, 2024
2 parents dcc918e + 0615d55 commit 573e19e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,21 @@ static int GetFallbackCharWidth( ImWchar c, const float scale )
return fontwidth * mk_wcwidth( c ) * scale;
}

void cataimgui::client::load_fonts( const std::unique_ptr<Font> &cata_font,
const std::array<SDL_Color, color_loader<SDL_Color>::COLOR_NAMES_COUNT> &windowsPalette )
void cataimgui::client::load_fonts( const Font_Ptr &cata_font,
const std::array<SDL_Color, color_loader<SDL_Color>::COLOR_NAMES_COUNT> &windowsPalette,
const std::vector<std::string> &typefaces )
{
ImGuiIO &io = ImGui::GetIO();
if( ImGui::GetIO().FontDefault == nullptr ) {
std::vector<std::string> typefaces;
ensure_unifont_loaded( typefaces );
std::vector<std::string> io_typefaces{ typefaces };
ensure_unifont_loaded( io_typefaces );

for( size_t index = 0; index < color_loader<SDL_Color>::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 );
Expand Down
5 changes: 3 additions & 2 deletions src/cata_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Font> &cata_font,
const std::array<SDL_Color, color_loader<SDL_Color>::COLOR_NAMES_COUNT> &windowsPalette );
void load_fonts( const std::unique_ptr<Font> &cata_fonts,
const std::array<SDL_Color, color_loader<SDL_Color>::COLOR_NAMES_COUNT> &windowsPalette,
const std::vector<std::string> &typeface );
#endif
~client();

Expand Down
2 changes: 1 addition & 1 deletion src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 573e19e

Please sign in to comment.