From a2885f278d88fec8539fe8d3b94f9ea733828169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 6 Apr 2024 01:17:17 -0300 Subject: [PATCH] Fallback loading the fallback font if the configured font has failed to load the font face. --- src/tools/ecode/ecode.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 192ab3c4b..afd0b5f26 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -3374,6 +3374,7 @@ static std::string getShellEnv( const std::string& env, const std::string& defSh FontTrueType* App::loadFont( const std::string& name, std::string fontPath, const std::string& fallback ) { + bool wasFallback = false; if ( FileSystem::isRelativePath( fontPath ) ) fontPath = mResPath + fontPath; #if EE_PLATFORM == EE_PLATFORM_ANDROID @@ -3383,12 +3384,26 @@ FontTrueType* App::loadFont( const std::string& name, std::string fontPath, if ( fontPath.empty() || !FileSystem::fileExists( fontPath ) ) { #endif fontPath = fallback; + wasFallback = true; if ( !fontPath.empty() && FileSystem::isRelativePath( fontPath ) ) fontPath = mResPath + fontPath; } if ( fontPath.empty() ) return nullptr; - return FontTrueType::New( name, fontPath ); + FontTrueType* font = FontTrueType::New( name ); + if ( font->loadFromFile( fontPath ) ) + return font; + eeSAFE_DELETE( font ); + // Failed to load original font? Try to fallback + if ( !fallback.empty() && !wasFallback ) { + if ( !fontPath.empty() && FileSystem::isRelativePath( fontPath ) ) + fontPath = mResPath + fontPath; + font = FontTrueType::New( name ); + if ( font->loadFromFile( fontPath ) ) + return font; + eeSAFE_DELETE( font ); + } + return nullptr; } void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDensity,