It's not impossible for the font face to fail loading

LoadFont()'s only usage already checked for nullptr to fallback, let's actually return nullptr on a failed load

Fixes sentry KICAD-8Z
Make the cause of sentry KICAD-95


(cherry picked from commit e8e407dfba)
This commit is contained in:
Marek Roszko 2023-02-13 20:04:55 -05:00 committed by Mark Roszko
parent 7a2a51ad44
commit a48eace90a
1 changed files with 7 additions and 4 deletions

View File

@ -90,26 +90,29 @@ wxString OUTLINE_FONT::FontLibraryVersion()
OUTLINE_FONT* OUTLINE_FONT::LoadFont( const wxString& aFontName, bool aBold, bool aItalic )
{
OUTLINE_FONT* font = new OUTLINE_FONT();
std::unique_ptr<OUTLINE_FONT> font = std::make_unique<OUTLINE_FONT>();
wxString fontFile;
using fc = fontconfig::FONTCONFIG;
fc::FF_RESULT retval = Fontconfig()->FindFont( aFontName, fontFile, aBold, aItalic );
if( retval == fc::FF_RESULT::FF_ERROR )
return nullptr;
if( retval == fc::FF_RESULT::FF_MISSING_BOLD || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
font->SetFakeBold();
if( retval == fc::FF_RESULT::FF_MISSING_ITAL || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
font->SetFakeItal();
if( retval != fc::FF_RESULT::FF_ERROR )
(void) font->loadFace( fontFile );
if( font->loadFace( fontFile ) != 0 )
return nullptr;
font->m_fontName = aFontName; // Keep asked-for name, even if we substituted.
font->m_fontFileName = fontFile;
return font;
return font.release();
}