Add support for loading fonts from files.
wxFont::AddPrivateFont() can now be used to load a font from a file for the applications private use. Update the font sample to show this. Closes #13568.
This commit is contained in:
committed by
Vadim Zeitlin
parent
760bd1bf4e
commit
547e40b114
@@ -24,6 +24,8 @@
|
||||
#include "wx/fontutil.h"
|
||||
#include "wx/fontmap.h"
|
||||
#include "wx/encinfo.h"
|
||||
#include "wx/filename.h"
|
||||
#include "wx/stdpaths.h"
|
||||
#include "wx/tokenzr.h"
|
||||
|
||||
|
||||
@@ -63,6 +65,42 @@ wxString wxNativeEncodingInfo::ToString() const
|
||||
return s;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Private Fonts
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// On OSX one can provide private fonts simply by putting the font files in
|
||||
// with the resources in your application bundle. So the API for adding fonts
|
||||
// does not do anything except checking that the file you pass to it actually
|
||||
// does exist and is in the correct directory.
|
||||
|
||||
bool wxFontBase::AddPrivateFont(const wxString& filename)
|
||||
{
|
||||
wxFileName fn(filename);
|
||||
if ( !fn.FileExists() )
|
||||
{
|
||||
wxLogError(_("Font file \"%s\" doesn't exist."), filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
wxString fontsDir;
|
||||
fontsDir << wxStandardPaths::Get().GetResourcesDir() << "/Fonts";
|
||||
if ( fn.GetPath() != fontsDir )
|
||||
{
|
||||
wxLogError(_("Font file \"%s\" cannot be used as it is not inside "
|
||||
"the font directory \"%s\"."), filename, fontsDir);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxFontBase::ActivatePrivateFonts()
|
||||
{
|
||||
// Nothing to do here.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helper functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user