Careful: symbol fonts have no language.
Also a bit of clean up to shut up a false-positive in Coverity (and clangd) on dereferencing a possibly (not) nullptr.
This commit is contained in:
parent
a170d3f006
commit
78cac128b7
|
@ -18,8 +18,6 @@
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <font/fontconfig.h>
|
#include <font/fontconfig.h>
|
||||||
#include <pgm_base.h>
|
#include <pgm_base.h>
|
||||||
#include <wx/log.h>
|
#include <wx/log.h>
|
||||||
|
@ -42,7 +40,7 @@ FONTCONFIG::FONTCONFIG()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
FONTCONFIG& Fontconfig()
|
FONTCONFIG* Fontconfig()
|
||||||
{
|
{
|
||||||
if( !g_config )
|
if( !g_config )
|
||||||
{
|
{
|
||||||
|
@ -50,7 +48,7 @@ FONTCONFIG& Fontconfig()
|
||||||
g_config = new FONTCONFIG();
|
g_config = new FONTCONFIG();
|
||||||
}
|
}
|
||||||
|
|
||||||
return *g_config;
|
return g_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,8 +135,14 @@ void FONTCONFIG::ListFonts( std::vector<std::string>& aFonts )
|
||||||
|
|
||||||
FcStrSet* langStrSet = FcLangSetGetLangs( langSet );
|
FcStrSet* langStrSet = FcLangSetGetLangs( langSet );
|
||||||
FcStrList* langStrList = FcStrListCreate( langStrSet );
|
FcStrList* langStrList = FcStrListCreate( langStrSet );
|
||||||
|
FcChar8* langStr = FcStrListNext( langStrList );
|
||||||
|
|
||||||
while( FcChar8* langStr = FcStrListNext( langStrList ) )
|
if( !langStr )
|
||||||
|
{
|
||||||
|
// Symbol fonts (Wingdings, etc.) have no language
|
||||||
|
langSupported = true;
|
||||||
|
}
|
||||||
|
else while( langStr )
|
||||||
{
|
{
|
||||||
wxString langWxStr( reinterpret_cast<char *>( langStr ) );
|
wxString langWxStr( reinterpret_cast<char *>( langStr ) );
|
||||||
const wxLanguageInfo* langInfo = wxLocale::FindLanguageInfo( langWxStr );
|
const wxLanguageInfo* langInfo = wxLocale::FindLanguageInfo( langWxStr );
|
||||||
|
@ -148,6 +152,8 @@ void FONTCONFIG::ListFonts( std::vector<std::string>& aFonts )
|
||||||
langSupported = true;
|
langSupported = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
langStr = FcStrListNext( langStrList );
|
||||||
}
|
}
|
||||||
|
|
||||||
FcStrListDone( langStrList );
|
FcStrListDone( langStrList );
|
||||||
|
@ -156,9 +162,6 @@ void FONTCONFIG::ListFonts( std::vector<std::string>& aFonts )
|
||||||
if( !langSupported )
|
if( !langSupported )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::ostringstream s;
|
|
||||||
s << family;
|
|
||||||
|
|
||||||
std::string theFile( reinterpret_cast<char *>( file ) );
|
std::string theFile( reinterpret_cast<char *>( file ) );
|
||||||
std::string theFamily( reinterpret_cast<char *>( family ) );
|
std::string theFamily( reinterpret_cast<char *>( family ) );
|
||||||
std::string theStyle( reinterpret_cast<char *>( style ) );
|
std::string theStyle( reinterpret_cast<char *>( style ) );
|
||||||
|
@ -167,7 +170,7 @@ void FONTCONFIG::ListFonts( std::vector<std::string>& aFonts )
|
||||||
if( theFamily.length() > 0 && theFamily.front() == '.' )
|
if( theFamily.length() > 0 && theFamily.front() == '.' )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto it = m_fonts.find( theFamily );
|
std::map<std::string, FONTINFO>::iterator it = m_fonts.find( theFamily );
|
||||||
|
|
||||||
if( it == m_fonts.end() )
|
if( it == m_fonts.end() )
|
||||||
m_fonts.insert( std::pair<std::string, FONTINFO>( theFamily, fontInfo ) );
|
m_fonts.insert( std::pair<std::string, FONTINFO>( theFamily, fontInfo ) );
|
||||||
|
|
|
@ -82,7 +82,7 @@ OUTLINE_FONT* OUTLINE_FONT::LoadFont( const wxString& aFontName, bool aBold, boo
|
||||||
if( aItalic )
|
if( aItalic )
|
||||||
qualifiedFontName << ":Italic";
|
qualifiedFontName << ":Italic";
|
||||||
|
|
||||||
if( Fontconfig().FindFont( qualifiedFontName, fontFile ) )
|
if( Fontconfig()->FindFont( qualifiedFontName, fontFile ) )
|
||||||
(void) font->loadFace( fontFile );
|
(void) font->loadFace( fontFile );
|
||||||
|
|
||||||
font->m_fontName = aFontName; // Keep asked-for name, even if we substituted.
|
font->m_fontName = aFontName; // Keep asked-for name, even if we substituted.
|
||||||
|
|
|
@ -29,7 +29,7 @@ FONT_CHOICE::FONT_CHOICE( wxWindow* aParent, int aId, wxPoint aPosition, wxSize
|
||||||
m_systemFontCount = wxChoice::GetCount();
|
m_systemFontCount = wxChoice::GetCount();
|
||||||
|
|
||||||
std::vector<std::string> fontNames;
|
std::vector<std::string> fontNames;
|
||||||
Fontconfig().ListFonts( fontNames );
|
Fontconfig()->ListFonts( fontNames );
|
||||||
|
|
||||||
wxArrayString menuList;
|
wxArrayString menuList;
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,17 @@ class FONTCONFIG
|
||||||
public:
|
public:
|
||||||
FONTCONFIG();
|
FONTCONFIG();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a fully-qualified font name ("Times:Bold:Italic") find the closest matching font
|
||||||
|
* and return its filepath in \a aFontFile.
|
||||||
|
*
|
||||||
|
* A return value of false indicates a serious error in the font system.
|
||||||
|
*/
|
||||||
bool FindFont( const wxString& aFontName, wxString& aFontFile );
|
bool FindFont( const wxString& aFontName, wxString& aFontFile );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List the current available font families.
|
||||||
|
*/
|
||||||
void ListFonts( std::vector<std::string>& aFonts );
|
void ListFonts( std::vector<std::string>& aFonts );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -45,6 +54,8 @@ private:
|
||||||
|
|
||||||
} // namespace fontconfig
|
} // namespace fontconfig
|
||||||
|
|
||||||
fontconfig::FONTCONFIG& Fontconfig();
|
|
||||||
|
fontconfig::FONTCONFIG* Fontconfig();
|
||||||
|
|
||||||
|
|
||||||
#endif //KICAD_FONTCONFIG_H
|
#endif //KICAD_FONTCONFIG_H
|
||||||
|
|
Loading…
Reference in New Issue