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:
Arthur Norman
2017-11-07 17:41:11 +01:00
committed by Vadim Zeitlin
parent 760bd1bf4e
commit 547e40b114
19 changed files with 366 additions and 8 deletions

View File

@@ -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
// ----------------------------------------------------------------------------