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:
@@ -34,6 +34,7 @@
|
|||||||
#endif // WX_PRECOMP
|
#endif // WX_PRECOMP
|
||||||
|
|
||||||
#include "wx/encinfo.h"
|
#include "wx/encinfo.h"
|
||||||
|
#include "wx/filename.h"
|
||||||
#include "wx/fontutil.h"
|
#include "wx/fontutil.h"
|
||||||
#include "wx/fontmap.h"
|
#include "wx/fontmap.h"
|
||||||
|
|
||||||
@@ -1083,3 +1084,49 @@ bool wxFont::IsFixedWidth() const
|
|||||||
// those meanings are the opposite of what the constant name implies."
|
// those meanings are the opposite of what the constant name implies."
|
||||||
return !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH);
|
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;
|
||||||
|
}
|
||||||
|
@@ -37,7 +37,6 @@
|
|||||||
#include "wx/dcprint.h"
|
#include "wx/dcprint.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/filename.h"
|
|
||||||
#include "wx/stack.h"
|
#include "wx/stack.h"
|
||||||
|
|
||||||
#include "wx/private/graphics.h"
|
#include "wx/private/graphics.h"
|
||||||
@@ -967,39 +966,13 @@ wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
wxArrayString gs_privateFontFileNames;
|
|
||||||
Gdiplus::PrivateFontCollection* gs_privateFonts = NULL;
|
Gdiplus::PrivateFontCollection* gs_privateFonts = NULL;
|
||||||
Gdiplus::FontFamily* gs_pFontFamily = NULL;
|
Gdiplus::FontFamily* gs_pFontFamily = NULL;
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
bool wxFontBase::AddPrivateFont(const wxString& filename)
|
// This function is defined in src/msw/font.cpp.
|
||||||
{
|
extern const wxArrayString& wxGetPrivateFontFileNames();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxGDIPlusFont implementation
|
// wxGDIPlusFont implementation
|
||||||
@@ -2343,13 +2316,14 @@ void wxGDIPlusRenderer::Load()
|
|||||||
m_loaded = 1;
|
m_loaded = 1;
|
||||||
|
|
||||||
// Make private fonts available to GDI+, if any.
|
// 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 )
|
if ( n )
|
||||||
{
|
{
|
||||||
gs_privateFonts = new Gdiplus::PrivateFontCollection();
|
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());
|
gs_privateFonts->AddFontFile(fname.t_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user