Cleanup and error reporting for fonts.
This commit is contained in:
parent
92d5a3e763
commit
a4349ae638
|
@ -57,9 +57,6 @@ const wxString& FONT::Name() const
|
|||
|
||||
FONT* FONT::getDefaultFont()
|
||||
{
|
||||
// FONT TODO: default font should be user-selectable in Eeschema but the KiCad stroke
|
||||
// font in Pcbnew
|
||||
|
||||
if( !s_defaultFont )
|
||||
s_defaultFont = STROKE_FONT::LoadFont( wxEmptyString );
|
||||
|
||||
|
@ -90,17 +87,9 @@ FONT* FONT::GetFont( const wxString& aFontName, bool aBold, bool aItalic )
|
|||
|
||||
bool FONT::IsStroke( const wxString& aFontName )
|
||||
{
|
||||
#if 0 // FONT TODO
|
||||
// Stroke fonts will be loaded under all four bold/italic combinations, so we only have
|
||||
// to check for one.
|
||||
std::tuple<wxString, bool, bool> key = { aFontName, false, false };
|
||||
|
||||
FONT* font = s_fontMap[key];
|
||||
|
||||
return font && font->IsStroke();
|
||||
#else
|
||||
// This would need a more complex implementation if we ever support more stroke fonts
|
||||
// than the KiCad Font.
|
||||
return aFontName == _( "Default Font" ) || aFontName == wxT( "KiCad Font" );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -159,21 +148,6 @@ void FONT::getLinePositions( const UTF8& aText, const VECTOR2I& aPosition,
|
|||
}
|
||||
|
||||
|
||||
void FONT::DrawText( KIGFX::GAL* aGal, const UTF8& aText, const VECTOR2I& aPosition,
|
||||
const TEXT_ATTRIBUTES& aAttributes ) const
|
||||
{
|
||||
// FONT TODO: do we need to set the attributes to the gal at all?
|
||||
aGal->SetHorizontalJustify( aAttributes.m_Halign );
|
||||
aGal->SetVerticalJustify( aAttributes.m_Valign );
|
||||
aGal->SetGlyphSize( aAttributes.m_Size );
|
||||
aGal->SetFontItalic( aAttributes.m_Italic );
|
||||
aGal->SetFontBold( aAttributes.m_Bold );
|
||||
aGal->SetTextMirrored( aAttributes.m_Mirrored );
|
||||
|
||||
Draw( aGal, aText, aPosition, aAttributes );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw a string.
|
||||
*
|
||||
|
|
|
@ -22,12 +22,13 @@
|
|||
#include <sstream>
|
||||
#include <font/fontconfig.h>
|
||||
#include <pgm_base.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <wx/log.h>
|
||||
|
||||
using namespace fontconfig;
|
||||
|
||||
static FONTCONFIG* g_config = nullptr;
|
||||
|
||||
|
||||
inline static FcChar8* wxStringToFcChar8( const wxString& str )
|
||||
{
|
||||
wxScopedCharBuffer const fcBuffer = str.ToUTF8();
|
||||
|
@ -37,10 +38,7 @@ inline static FcChar8* wxStringToFcChar8( const wxString& str )
|
|||
|
||||
FONTCONFIG::FONTCONFIG()
|
||||
{
|
||||
m_config = FcInitLoadConfigAndFonts();
|
||||
|
||||
wxString configDirPath( Pgm().GetSettingsManager().GetUserSettingsPath() + wxT( "/fonts" ) );
|
||||
FcConfigAppFontAddDir( nullptr, wxStringToFcChar8( configDirPath ) );
|
||||
(void) FcInitLoadConfigAndFonts();
|
||||
};
|
||||
|
||||
|
||||
|
@ -74,12 +72,34 @@ bool FONTCONFIG::FindFont( const wxString& aFontName, wxString& aFontFile )
|
|||
if( FcPatternGetString( font, FC_FILE, 0, &file ) == FcResultMatch )
|
||||
{
|
||||
aFontFile = wxString::FromUTF8( (char*) file );
|
||||
|
||||
FcChar8* family = nullptr;
|
||||
FcChar8* style = nullptr;
|
||||
|
||||
FcPatternGetString( font, FC_FAMILY, 0, &family );
|
||||
FcPatternGetString( font, FC_STYLE, 0, &style );
|
||||
|
||||
wxString fontName( family );
|
||||
wxString styleStr( style );
|
||||
|
||||
if( !styleStr.IsEmpty() )
|
||||
{
|
||||
styleStr.Replace( " ", ":" );
|
||||
fontName += ":" + styleStr;
|
||||
}
|
||||
|
||||
if( aFontName.CmpNoCase( fontName ) != 0 )
|
||||
wxLogWarning( _( "Font '%s' not found; substituting '%s'." ), aFontName, fontName );
|
||||
|
||||
ok = true;
|
||||
}
|
||||
|
||||
FcPatternDestroy( font );
|
||||
}
|
||||
|
||||
if( !ok )
|
||||
wxLogWarning( _( "Error loading font '%s'." ), aFontName );
|
||||
|
||||
FcPatternDestroy( pat );
|
||||
return ok;
|
||||
}
|
||||
|
|
|
@ -62,11 +62,7 @@ OUTLINE_FONT::OUTLINE_FONT() :
|
|||
m_faceSize( 16 )
|
||||
{
|
||||
if( !m_freeType )
|
||||
{
|
||||
//FT_Error ft_error = FT_Init_FreeType( &m_freeType );
|
||||
// TODO: handle ft_error
|
||||
FT_Init_FreeType( &m_freeType );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,49 +73,25 @@ OUTLINE_FONT* OUTLINE_FONT::LoadFont( const wxString& aFontName, bool aBold, boo
|
|||
wxString fontFile;
|
||||
wxString qualifiedFontName = aFontName;
|
||||
|
||||
if( !aBold && !aItalic )
|
||||
qualifiedFontName << ":Regular";
|
||||
|
||||
if( aBold )
|
||||
qualifiedFontName << ":bold";
|
||||
qualifiedFontName << ":Bold";
|
||||
|
||||
if( aItalic )
|
||||
qualifiedFontName << ":italic";
|
||||
qualifiedFontName << ":Italic";
|
||||
|
||||
if( Fontconfig().FindFont( qualifiedFontName, fontFile ) )
|
||||
(void) font->loadFace( fontFile );
|
||||
else
|
||||
(void) font->loadFontSimple( aFontName );
|
||||
|
||||
font->m_fontName = aFontName; // Keep asked-for name, even if we substituted.
|
||||
font->m_fontFileName = fontFile;
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
|
||||
bool OUTLINE_FONT::loadFontSimple( const wxString& aFontFileName )
|
||||
{
|
||||
wxFileName fontFile( aFontFileName );
|
||||
wxString fileName = fontFile.GetFullPath();
|
||||
// TODO: handle ft_error properly (now we just return false if load does not succeed)
|
||||
FT_Error ft_error = loadFace( fileName );
|
||||
|
||||
if( ft_error == FT_Err_Unknown_File_Format )
|
||||
{
|
||||
wxLogWarning( _( "The font file %s could be opened and read, "
|
||||
"but it appears that its font format is unsupported." ),
|
||||
fileName );
|
||||
}
|
||||
else if( ft_error )
|
||||
{
|
||||
wxLogWarning( _( "Unknown font error (%d) " ), ft_error );
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fontName = aFontFileName;
|
||||
m_fontFileName = fileName;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
FT_Error OUTLINE_FONT::loadFace( const wxString& aFontFileName )
|
||||
{
|
||||
m_faceScaler = m_faceSize * 64;
|
||||
|
@ -140,9 +112,6 @@ FT_Error OUTLINE_FONT::loadFace( const wxString& aFontFileName )
|
|||
{
|
||||
FT_Select_Charmap( m_subscriptFace, FT_Encoding::FT_ENCODING_UNICODE );
|
||||
FT_Set_Char_Size( m_subscriptFace, 0, m_subscriptFaceScaler, 0, 0 );
|
||||
|
||||
m_fontName = wxString( m_face->family_name );
|
||||
m_fontFileName = aFontFileName;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -132,9 +132,6 @@ public:
|
|||
Draw( aGal, aText, aPosition, VECTOR2I( 0, 0 ), aAttributes );
|
||||
}
|
||||
|
||||
virtual void DrawText( KIGFX::GAL* aGal, const UTF8& aText, const VECTOR2I& aPosition,
|
||||
const TEXT_ATTRIBUTES& aAttributes ) const;
|
||||
|
||||
/**
|
||||
* Compute the boundary limits of aText (the bounding box of all shapes).
|
||||
*
|
||||
|
|
|
@ -40,7 +40,6 @@ public:
|
|||
void ListFonts( std::vector<std::string>& aFonts );
|
||||
|
||||
private:
|
||||
FcConfig* m_config;
|
||||
std::map<std::string, FONTINFO> m_fonts;
|
||||
};
|
||||
|
||||
|
|
|
@ -127,8 +127,6 @@ public:
|
|||
protected:
|
||||
FT_Error loadFace( const wxString& aFontFileName );
|
||||
|
||||
bool loadFontSimple( const wxString& aFontFileName );
|
||||
|
||||
BOX2I getBoundingBox( const std::vector<std::unique_ptr<GLYPH>>& aGlyphs ) const;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue