From 149807db263929d58b5805ad6534ffaa37aff72b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 18:02:58 +0100 Subject: [PATCH] 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(). --- src/msw/font.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++ src/msw/graphics.cpp | 38 ++++++----------------------------- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/msw/font.cpp b/src/msw/font.cpp index a5243d1181..6116920108 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -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; +} diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index fd5957e59a..ed4f4e05bf 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -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()); }