mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-09 08:19:25 +03:00
Fallback loading the fallback font if the configured font has failed to load the font face.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user