Move wxMSW wxFont private font methods to src/msw/font.cpp

This ensures that they will be defined and work even when building with
wxUSE_GRAPHICS_CONTEXT==0 (as can happen even by default with old MinGW
versions).

Private fonts are still made available to wxGraphicsContext as well by
providing access to them from GDI+ code via wxGetPrivateFontFileNames().
This commit is contained in:
Vadim Zeitlin
2017-11-07 18:02:58 +01:00
parent 4145a30e06
commit 149807db26
2 changed files with 53 additions and 32 deletions

View File

@@ -34,6 +34,7 @@
#endif // WX_PRECOMP
#include "wx/encinfo.h"
#include "wx/filename.h"
#include "wx/fontutil.h"
#include "wx/fontmap.h"
@@ -1083,3 +1084,49 @@ bool wxFont::IsFixedWidth() const
// those meanings are the opposite of what the constant name implies."
return !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH);
}
// ----------------------------------------------------------------------------
// Private fonts support
// ----------------------------------------------------------------------------
namespace
{
// Contains the file names of all fonts added by AddPrivateFont().
wxArrayString gs_privateFontFileNames;
} // anonymous namespace
// Accessor for use in src/msw/graphics.cpp only.
extern const wxArrayString& wxGetPrivateFontFileNames()
{
return gs_privateFontFileNames;
}
bool wxFontBase::AddPrivateFont(const wxString& filename)
{
if ( !wxFileName::FileExists(filename) )
{
wxLogError(_("Font file \"%s\" doesn't exist."), filename);
return false;
}
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;
}

View File

@@ -37,7 +37,6 @@
#include "wx/dcprint.h"
#endif
#include "wx/filename.h"
#include "wx/stack.h"
#include "wx/private/graphics.h"
@@ -967,39 +966,13 @@ wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
namespace
{
wxArrayString gs_privateFontFileNames;
Gdiplus::PrivateFontCollection* gs_privateFonts = NULL;
Gdiplus::FontFamily* gs_pFontFamily = NULL;
} // anonymous namespace
bool wxFontBase::AddPrivateFont(const wxString& filename)
{
if ( !wxFileName::FileExists(filename) )
{
wxLogError(_("Font file \"%s\" doesn't exist."), filename);
return false;
}
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;
}
// This function is defined in src/msw/font.cpp.
extern const wxArrayString& wxGetPrivateFontFileNames();
//-----------------------------------------------------------------------------
// wxGDIPlusFont implementation
@@ -2343,13 +2316,14 @@ void wxGDIPlusRenderer::Load()
m_loaded = 1;
// Make private fonts available to GDI+, if any.
const int n = gs_privateFontFileNames.size();
const wxArrayString& privateFonts = wxGetPrivateFontFileNames();
const size_t n = privateFonts.size();
if ( n )
{
gs_privateFonts = new Gdiplus::PrivateFontCollection();
for ( int i = 0 ; i < n; i++ )
for ( size_t i = 0 ; i < n; i++ )
{
const wxString& fname = gs_privateFontFileNames[i];
const wxString& fname = privateFonts[i];
gs_privateFonts->AddFontFile(fname.t_str());
}