Remove useless wxFont::ActivatePrivateFonts()
Just "activate" the font immediately when adding it using AddPrivateFont(), nothing seems to be gained from having two functions and it just makes things more complicated both when implementing and when using the API.
This commit is contained in:
@@ -82,12 +82,9 @@ system. On Macintosh/OSX this can be arranged by placing the desired fonts
|
||||
within the Application Bundle in Contents/Resources/Fonts and using
|
||||
the ATSApplicationFontsPath key to point there. The full details of the
|
||||
procedure there can be found as OSX developer resources. For the GTK+ and
|
||||
Windows ports it is possible to add TrueType fonts at run-time using
|
||||
a sequence of calls to wxFont::AddPrivateFont() to give the names of files
|
||||
containing font data, followed by a call to wxFont::ActivatePrivateFonts()
|
||||
to complete the process of making the fonts available. These functions
|
||||
return false if they fail. They should be called just once before any
|
||||
graphics contexts have been created or other activity liable to use fonts
|
||||
has happened.
|
||||
Windows ports it is possible to add TrueType fonts from arbitrary locations at
|
||||
run-time using wxFont::AddPrivateFont(). Notice that under MSW this function
|
||||
should be called before creating the first wxGraphicsContext object if you want
|
||||
the private font to be usable from it.
|
||||
|
||||
*/
|
||||
|
@@ -328,11 +328,12 @@ public:
|
||||
// from the string representation of wxNativeFontInfo
|
||||
static wxFont *New(const wxString& strNativeFontDesc);
|
||||
|
||||
// These functions can be used to load private fonts if supported by this
|
||||
// platform (wxHAS_PRIVATE_FONTS is defined): first add one or more files
|
||||
// and then activate all of them at once.
|
||||
// Load the font from the given file and return true on success or false on
|
||||
// error (an error message will be logged in this case, unless there is no
|
||||
// support for private fonts at all in the current port, in which case
|
||||
// wxHAS_PRIVATE_FONTS will not be defined allowing to check for this at
|
||||
// compile-time).
|
||||
static bool AddPrivateFont(const wxString& filename);
|
||||
static bool ActivatePrivateFonts();
|
||||
|
||||
// comparison
|
||||
bool operator==(const wxFont& font) const;
|
||||
|
@@ -678,30 +678,25 @@ public:
|
||||
@c ATSApplicationFontsPath to @c Fonts value in your @c Info.plist
|
||||
file. See also wxStandardPaths::GetResourcesDir().
|
||||
|
||||
Notice that this method must be called before any graphics contexts
|
||||
have been created.
|
||||
Under MSW this method must be called before any wxGraphicsContext
|
||||
objects have been created, otherwise the private font won't be usable
|
||||
from them.
|
||||
|
||||
Under Unix this method requires Pango 1.38 or later and will return @a
|
||||
false and log an error message explaining the problem if this
|
||||
requirement is not satisfied either at compile- or run-time.
|
||||
|
||||
Currently this method is implemented for all major platforms but you
|
||||
may also test for @c wxHAS_PRIVATE_FONTS preprocessor symbol: if it is
|
||||
not defined, this function and ActivatePrivatefonts() are not
|
||||
implemented at all and always simply return false.
|
||||
not defined, this function is not implemented at all and simply always
|
||||
returns false.
|
||||
|
||||
@return @true if the font was added and ActivatePrivatefonts() should
|
||||
be called next or @false if adding it failed.
|
||||
@return @true if the font was added and can now be used.
|
||||
|
||||
@since 3.1.1
|
||||
*/
|
||||
static bool AddPrivateFont(const wxString& filename);
|
||||
|
||||
/**
|
||||
Make all fonts registered by AddPrivateFont() actually available.
|
||||
|
||||
@return @true if the private fonts can now be used or @false on error.
|
||||
|
||||
@since 3.1.1
|
||||
*/
|
||||
static bool ActivatePrivatefonts();
|
||||
|
||||
/**
|
||||
Gets the point size.
|
||||
|
||||
|
@@ -426,10 +426,6 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||
{
|
||||
wxLogWarning("Failed to add private font from \"%s\"", privfont);
|
||||
}
|
||||
else if ( !wxFont::ActivatePrivateFonts() )
|
||||
{
|
||||
wxLogWarning("Failed to activate the private fonts");
|
||||
}
|
||||
else
|
||||
{
|
||||
menuSelect->AppendSeparator();
|
||||
|
@@ -1148,9 +1148,4 @@ bool wxFontBase::AddPrivateFont(const wxString& WXUNUSED(filename))
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxFontBase::ActivatePrivateFonts()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // !wxHAS_PRIVATE_FONTS
|
||||
|
@@ -601,42 +601,41 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxFcConfigDestroyModule, wxModule);
|
||||
|
||||
bool wxFontBase::AddPrivateFont(const wxString& filename)
|
||||
{
|
||||
if ( !gs_fcConfig )
|
||||
{
|
||||
gs_fcConfig = FcInitLoadConfigAndFonts();
|
||||
if ( !gs_fcConfig )
|
||||
{
|
||||
wxLogError(_("Failed to create font configuration object."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !FcConfigAppFontAddFile(gs_fcConfig,
|
||||
reinterpret_cast<const FcChar8*>(
|
||||
static_cast<const char*>(filename.utf8_str())
|
||||
)) )
|
||||
{
|
||||
wxLogError(_("Failed to add custom font \"%s\"."), filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxFontBase::ActivatePrivateFonts()
|
||||
{
|
||||
wxGtkObject<PangoContext> context(wxGetPangoContext());
|
||||
PangoFontMap* const fmap = pango_context_get_font_map(context);
|
||||
if ( !fmap || !PANGO_IS_FC_FONT_MAP(fmap) )
|
||||
{
|
||||
wxLogError(_("Failed to register font configuration using private fonts."));
|
||||
return false;
|
||||
}
|
||||
|
||||
wxString why;
|
||||
|
||||
// All this code only works if we have pango_context_get_font_map() which
|
||||
// is new in 1.38, so don't bother compiling -- or running -- it if this is
|
||||
// not the case.
|
||||
#if PANGO_VERSION_CHECK(1,38,0)
|
||||
if ( wx_pango_version_check(1,38,0) == NULL )
|
||||
{
|
||||
if ( !gs_fcConfig )
|
||||
{
|
||||
gs_fcConfig = FcInitLoadConfigAndFonts();
|
||||
if ( !gs_fcConfig )
|
||||
{
|
||||
wxLogError(_("Failed to create font configuration object."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !FcConfigAppFontAddFile(gs_fcConfig,
|
||||
reinterpret_cast<const FcChar8*>(
|
||||
static_cast<const char*>(filename.utf8_str())
|
||||
)) )
|
||||
{
|
||||
wxLogError(_("Failed to add custom font \"%s\"."), filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
wxGtkObject<PangoContext> context(wxGetPangoContext());
|
||||
PangoFontMap* const fmap = pango_context_get_font_map(context);
|
||||
if ( !fmap || !PANGO_IS_FC_FONT_MAP(fmap) )
|
||||
{
|
||||
wxLogError(_("Failed to register font configuration using private fonts."));
|
||||
return false;
|
||||
}
|
||||
|
||||
PangoFcFontMap* const fcfmap = PANGO_FC_FONT_MAP(fmap);
|
||||
pango_fc_font_map_set_config(fcfmap, gs_fcConfig);
|
||||
|
||||
|
@@ -35,7 +35,6 @@
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/encinfo.h"
|
||||
#include "wx/filename.h"
|
||||
#include "wx/fontutil.h"
|
||||
#include "wx/fontmap.h"
|
||||
|
||||
@@ -1122,28 +1121,13 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxPrivateFontsListModule, wxModule);
|
||||
|
||||
bool wxFontBase::AddPrivateFont(const wxString& filename)
|
||||
{
|
||||
if ( !wxFileName::FileExists(filename) )
|
||||
if ( !AddFontResourceEx(filename.t_str(), FR_PRIVATE, 0) )
|
||||
{
|
||||
wxLogError(_("Font file \"%s\" doesn't exist."), filename);
|
||||
wxLogSysError(_("Font file \"%s\" couldn't be loaded"), filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remember it for use in wxGDIPlusRenderer::Load().
|
||||
gs_privateFontFileNames.Add(filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxFontBase::ActivatePrivateFonts()
|
||||
{
|
||||
const int n = gs_privateFontFileNames.size();
|
||||
for ( int i = 0 ; i < n; i++ )
|
||||
{
|
||||
const wxString& fname = gs_privateFontFileNames[i];
|
||||
if ( !AddFontResourceEx(fname.t_str(), FR_PRIVATE, 0) )
|
||||
{
|
||||
wxLogSysError(_("Font file \"%s\" couldn't be loaded"),
|
||||
fname);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -95,12 +95,6 @@ bool wxFontBase::AddPrivateFont(const wxString& filename)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxFontBase::ActivatePrivateFonts()
|
||||
{
|
||||
// Nothing to do here.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helper functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user