From ebcaf616564c594e84bf2777e1e4b6b3f2219c5a Mon Sep 17 00:00:00 2001 From: alef Date: Mon, 26 Aug 2024 04:15:10 +0200 Subject: [PATCH] Check the typeface file exists (#75937) * Check the typeface file exists * Obey lint --- src/cata_imgui.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index 78dc9e4c9dc27..82d73e1f40c45 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -269,7 +269,13 @@ void cataimgui::client::load_fonts( const Font_Ptr &cata_font, ImU32 rgb = sdlCol.b << 16 | sdlCol.g << 8 | sdlCol.r; sdlColorsToCata[rgb] = index; } - io.FontDefault = io.Fonts->AddFontFromFileTTF( io_typefaces[0].c_str(), fontheight, nullptr, + auto it = std::find_if( io_typefaces.begin(), + io_typefaces.end(), []( const std::string & io_typeface ) { + std::filesystem::path path( io_typeface ); + return std::filesystem::exists( path ); + } ); + std::string existing_typeface = *it; + io.FontDefault = io.Fonts->AddFontFromFileTTF( existing_typeface.c_str(), fontheight, nullptr, io.Fonts->GetGlyphRangesDefault() ); io.Fonts->Fonts[0]->SetFallbackStrSizeCallback( GetFallbackStrWidth ); io.Fonts->Fonts[0]->SetFallbackCharSizeCallback( GetFallbackCharWidth );