From 142b3bc26a6e93f5857bc053c7748b2c845c4a8e Mon Sep 17 00:00:00 2001
From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= <vslavik@fastmail.fm>
Date: Sat, 6 Apr 2002 15:04:27 +0000
Subject: [PATCH] added wxFontMapper::Get/Set

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14969 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/changes.txt            |  2 ++
 docs/latex/wx/config.tex    |  4 +--
 docs/latex/wx/fontmap.tex   | 38 ++++++++++++++++++++++------
 docs/latex/wx/tnoneng.tex   |  2 +-
 include/wx/fontmap.h        | 11 ++++++++-
 samples/console/console.cpp |  6 ++---
 samples/font/font.cpp       |  8 +++---
 src/common/fontcmn.cpp      |  4 +--
 src/common/fontmap.cpp      | 49 +++++++++++++++++++++----------------
 src/common/intl.cpp         |  4 +--
 src/common/strconv.cpp      |  4 +--
 src/html/helpdata.cpp       |  2 +-
 src/html/m_meta.cpp         |  2 +-
 src/html/winpars.cpp        | 10 ++++----
 src/mac/carbon/fontenum.cpp |  2 +-
 src/mac/fontenum.cpp        |  2 +-
 src/mgl/dc.cpp              |  2 +-
 src/msw/font.cpp            |  2 +-
 src/msw/fontenum.cpp        |  2 +-
 src/msw/utils.cpp           |  2 +-
 src/os2/font.cpp            |  2 +-
 src/os2/fontenum.cpp        |  2 +-
 src/os2/wx23.def            |  1 -
 src/unix/fontenum.cpp       |  2 +-
 src/unix/fontutil.cpp       |  2 +-
 25 files changed, 104 insertions(+), 63 deletions(-)

diff --git a/docs/changes.txt b/docs/changes.txt
index 5361f5ac65..ea0a35db24 100644
--- a/docs/changes.txt
+++ b/docs/changes.txt
@@ -112,6 +112,8 @@ wxBase:
 - wxLocale now works in Unicode mode
 - wxLocale can now load message catalogs in arbitrary encoding
 - fixed the bug related to the redrawing on resize introduced in 2.3.2
+- added static wxFontMapper::Get() accessor (use of wxTheFontMapper is now
+  deprecated)
 
 Unix (Base/GUI):
 
diff --git a/docs/latex/wx/config.tex b/docs/latex/wx/config.tex
index f349c6f0fd..920d830406 100644
--- a/docs/latex/wx/config.tex
+++ b/docs/latex/wx/config.tex
@@ -434,7 +434,7 @@ destructor)
 
 \membersection{wxConfigBase::Get}\label{wxconfigbaseget}
 
-\func{wxConfigBase *}{Get}{\param{bool }{CreateOnDemand = TRUE}}
+\func{static wxConfigBase *}{Get}{\param{bool }{CreateOnDemand = TRUE}}
 
 Get the current config object. If there is no current object and
 {\it CreateOnDemand} is TRUE, creates one
@@ -684,7 +684,7 @@ exists.
 
 \membersection{wxConfigBase::Set}\label{wxconfigbaseset}
 
-\func{wxConfigBase *}{Set}{\param{wxConfigBase *}{pConfig}}
+\func{static wxConfigBase *}{Set}{\param{wxConfigBase *}{pConfig}}
 
 Sets the config object as the current one, returns the pointer to the previous
 current object (both the parameter and returned value may be NULL)
diff --git a/docs/latex/wx/fontmap.tex b/docs/latex/wx/fontmap.tex
index fbf85fdf19..fe252bc35c 100644
--- a/docs/latex/wx/fontmap.tex
+++ b/docs/latex/wx/fontmap.tex
@@ -23,10 +23,6 @@ and "interactive" is FALSE or user denied to choose any replacement),
 the class queries \helpref{wxEncodingConverter}{wxencodingconverter} 
 for "equivalent" encodings (e.g. iso8859-2 and cp1250) and tries them.
 
-\wxheading{Global variables}
-
-{\tt wxFontMapper *wxTheFontMapper} is defined.
-
 \wxheading{Using wxFontMapper in conjunction with wxEncodingConverter}
 
 If you need to display text in encoding which is not available at
@@ -39,11 +35,11 @@ and convert the text to this encoding
 Following code snippet demonstrates it:
 
 \begin{verbatim}
-if (!wxTheFontMapper->IsEncodingAvailable(enc, facename))
+if (!wxFontMapper::Get()->IsEncodingAvailable(enc, facename))
 {
    wxFontEncoding alternative;
-   if (wxTheFontMapper->GetAltForEncoding(enc, &alternative,
-                                          facename, FALSE))
+   if (wxFontMapper::Get()->GetAltForEncoding(enc, &alternative,
+                                              facename, FALSE))
    {
        wxEncodingConverter encconv;
        if (!encconv.Init(enc, alternative))
@@ -79,12 +75,28 @@ No base class
 
 Default ctor.
 
+\wxheading{Note}
+
+The preferred way of creating a wxFontMapper instance is to call 
+\helpref{wxFontMapper::Get}{wxfontmapperget}.
+
 \membersection{wxFontMapper::\destruct{wxFontMapper}}\label{wxfontmapperdtor}
 
 \func{}{\destruct{wxFontMapper}}{\void}
 
 Virtual dtor for a base class.
 
+\membersection{wxFontMapper::Get}\label{wxfontmapperget}
+
+\func{static wxFontMapper *}{Get}{\void}
+
+Get the current font mapper object. If there is no current object, creates
+one.
+
+\wxheading{See also}
+
+\helpref{wxFontMapper::Set}{wxfontmapperset}
+
 \membersection{wxFontMapper::GetAltForEncoding}\label{wxfontmappergetaltforencoding}
 
 \func{bool}{GetAltForEncoding}{\param{wxFontEncoding }{encoding}, \param{wxNativeEncodingInfo* }{info}, \param{const wxString\& }{facename = wxEmptyString}, \param{bool }{interactive = TRUE}}
@@ -139,6 +151,18 @@ The parent window for modal dialogs.
 
 The title for the dialogs (note that default is quite reasonable).
 
+\membersection{wxFontMapper::Set}\label{wxfontmapperset}
+
+\func{static wxFontMapper *}{Set}{\param{wxFontMapper *}{mapper}}
+
+Set the current font mapper object and return previous one (may be NULL).
+This method is only useful if you want to plug-in an alternative font mapper
+into wxWindows.
+
+\wxheading{See also}
+
+\helpref{wxFontMapper::Get}{wxfontmapperget}
+
 \membersection{wxFontMapper::SetConfig}\label{wxfontmappersetconfig}
 
 \func{void}{SetConfig}{\param{wxConfigBase* }{config}}
diff --git a/docs/latex/wx/tnoneng.tex b/docs/latex/wx/tnoneng.tex
index afae77b9c8..084c807e94 100644
--- a/docs/latex/wx/tnoneng.tex
+++ b/docs/latex/wx/tnoneng.tex
@@ -94,7 +94,7 @@ You can use \helpref{wxEncodingConverter}{wxencodingconverter} and
 \helpref{wxFontMapper}{wxfontmapper} to display text:
 
 \begin{verbatim}
-if (!wxTheFontMapper->IsEncodingAvailable(enc, facename))
+if (!wxFontMapper::Get()->IsEncodingAvailable(enc, facename))
 {
    wxFontEncoding alternative;
    if (wxTheFontMapper->GetAltForEncoding(enc, &alternative, 
diff --git a/include/wx/fontmap.h b/include/wx/fontmap.h
index 70691e8afb..53edf7f17c 100644
--- a/include/wx/fontmap.h
+++ b/include/wx/fontmap.h
@@ -59,6 +59,11 @@ public:
     // virtual dtor for a base class
     virtual ~wxFontMapper();
 
+    // return instance of the wxFontMapper singleton
+    static wxFontMapper *Get();
+    // set the sigleton to 'mapper' instance and return previous one
+    static wxFontMapper *Set(wxFontMapper *mapper);
+
 #if wxUSE_GUI
     // find an alternative for the given encoding (which is supposed to not be
     // available on this system). If successful, return TRUE and fill info
@@ -180,6 +185,9 @@ protected:
 #endif // wxUSE_GUI
 
     friend class wxFontMapperPathChanger;
+    
+private:
+    static wxFontMapper *sm_instance;
 };
 
 // ----------------------------------------------------------------------------
@@ -187,7 +195,8 @@ protected:
 // ----------------------------------------------------------------------------
 
 // the default font mapper for wxWindows programs
-WXDLLEXPORT_DATA(extern wxFontMapper *) wxTheFontMapper;
+// do NOT use! This is for backward compatibility, use wxFontMapper::Get() instead
+#define wxTheFontMapper (wxFontMapper::Get())
 
 #endif // wxUSE_FONTMAP
 
diff --git a/samples/console/console.cpp b/samples/console/console.cpp
index 53990de434..7a9e0bb1af 100644
--- a/samples/console/console.cpp
+++ b/samples/console/console.cpp
@@ -184,11 +184,11 @@ static void TestCharset()
 
     for ( size_t n = 0; n < WXSIZEOF(charsets); n++ )
     {
-        wxFontEncoding enc = wxTheFontMapper->CharsetToEncoding(charsets[n]);
+        wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(charsets[n]);
         wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"),
                  charsets[n],
-                 wxTheFontMapper->GetEncodingName(enc).c_str(),
-                 wxTheFontMapper->GetEncodingDescription(enc).c_str());
+                 wxFontMapper::Get()->GetEncodingName(enc).c_str(),
+                 wxFontMapper::Get()->GetEncodingDescription(enc).c_str());
     }
 }
 
diff --git a/samples/font/font.cpp b/samples/font/font.cpp
index 6c9dff7a50..b92b86b255 100644
--- a/samples/font/font.cpp
+++ b/samples/font/font.cpp
@@ -632,7 +632,7 @@ void MyFrame::OnViewMsg(wxCommandEvent& WXUNUSED(event))
     }
 
     // ok, now get the corresponding encoding
-    wxFontEncoding fontenc = wxTheFontMapper->CharsetToEncoding(charset);
+    wxFontEncoding fontenc = wxFontMapper::Get()->CharsetToEncoding(charset);
     if ( fontenc == wxFONTENCODING_SYSTEM )
     {
         wxLogError(wxT("Charset '%s' is unsupported."), charset.c_str());
@@ -642,11 +642,11 @@ void MyFrame::OnViewMsg(wxCommandEvent& WXUNUSED(event))
     m_textctrl->LoadFile(filename);
 
     if ( fontenc == wxFONTENCODING_UTF8 ||
-            !wxTheFontMapper->IsEncodingAvailable(fontenc) )
+            !wxFontMapper::Get()->IsEncodingAvailable(fontenc) )
     {
         // try to find some similar encoding:
         wxFontEncoding encAlt;
-        if ( wxTheFontMapper->GetAltForEncoding(fontenc, &encAlt) )
+        if ( wxFontMapper::Get()->GetAltForEncoding(fontenc, &encAlt) )
         {
             wxEncodingConverter conv;
 
@@ -732,7 +732,7 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
     fontInfo.Printf(wxT("Font size is %d points, family: %s, encoding: %s"),
                     m_font.GetPointSize(),
                     m_font.GetFamilyString().c_str(),
-                    wxTheFontMapper->
+                    wxFontMapper::Get()->
                         GetEncodingDescription(m_font.GetEncoding()).c_str());
 
     dc.DrawText(fontInfo, x, y);
diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp
index 50b3b19db8..9f09b4c8e1 100644
--- a/src/common/fontcmn.cpp
+++ b/src/common/fontcmn.cpp
@@ -475,7 +475,7 @@ wxString wxNativeFontInfo::ToUserString() const
     wxFontEncoding enc = GetEncoding();
     if ( enc != wxFONTENCODING_DEFAULT && enc != wxFONTENCODING_SYSTEM )
     {
-        desc << _T(' ') << wxTheFontMapper->GetEncodingName(enc);
+        desc << _T(' ') << wxFontMapper::Get()->GetEncodingName(enc);
     }
 #endif // wxUSE_FONTMAP
 
@@ -528,7 +528,7 @@ bool wxNativeFontInfo::FromUserString(const wxString& s)
             SetPointSize(size);
         }
 #if wxUSE_FONTMAP
-        else if ( (encoding = wxTheFontMapper->CharsetToEncoding(token, FALSE))
+        else if ( (encoding = wxFontMapper::Get()->CharsetToEncoding(token, FALSE))
                     != wxFONTENCODING_DEFAULT )
         {
             SetEncoding(encoding);
diff --git a/src/common/fontmap.cpp b/src/common/fontmap.cpp
index ab990ef8eb..c976d72af6 100644
--- a/src/common/fontmap.cpp
+++ b/src/common/fontmap.cpp
@@ -178,27 +178,6 @@ static const wxChar* gs_encodingNames[] =
     wxT( "utf-8" ),
 };
 
-// ----------------------------------------------------------------------------
-// global data
-// ----------------------------------------------------------------------------
-
-wxFontMapper * wxTheFontMapper = NULL;
-
-class wxFontMapperModule: public wxModule
-{
-public:
-    wxFontMapperModule() : wxModule() { }
-    virtual bool OnInit() { wxTheFontMapper = new wxFontMapper; return TRUE; }
-    virtual void OnExit()
-    {
-        delete wxTheFontMapper;
-        wxTheFontMapper = NULL;
-    }
-
-    DECLARE_DYNAMIC_CLASS(wxFontMapperModule)
-};
-
-IMPLEMENT_DYNAMIC_CLASS(wxFontMapperModule, wxModule)
 
 // ----------------------------------------------------------------------------
 // private classes
@@ -256,6 +235,34 @@ wxFontMapper::~wxFontMapper()
 #endif // wxUSE_CONFIG
 }
 
+wxFontMapper *wxFontMapper::sm_instance = NULL;
+
+/*static*/ wxFontMapper *wxFontMapper::Get()
+{
+    if ( !sm_instance )
+        sm_instance = new wxFontMapper;
+    return sm_instance;
+}
+
+/*static*/ wxFontMapper *wxFontMapper::Set(wxFontMapper *mapper)
+{
+    wxFontMapper *old = sm_instance;
+    sm_instance = mapper;
+    return old;
+}
+
+class wxFontMapperModule: public wxModule
+{
+public:
+    wxFontMapperModule() : wxModule() {}
+    virtual bool OnInit() { return TRUE; }
+    virtual void OnExit() { delete wxFontMapper::Set(NULL); }
+
+    DECLARE_DYNAMIC_CLASS(wxFontMapperModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxFontMapperModule, wxModule)
+
 // ----------------------------------------------------------------------------
 // customisation
 // ----------------------------------------------------------------------------
diff --git a/src/common/intl.cpp b/src/common/intl.cpp
index 168c333343..8f36b359d7 100644
--- a/src/common/intl.cpp
+++ b/src/common/intl.cpp
@@ -444,7 +444,7 @@ void wxMsgCatalogFile::FillHash(wxMessagesHash& hash, bool convertEncoding) cons
     if ( convertEncoding )
     {
         wxFontEncoding targetEnc = wxFONTENCODING_SYSTEM;
-        wxFontEncoding enc = wxTheFontMapper->CharsetToEncoding(charset, FALSE);
+        wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(charset, FALSE);
         if ( enc == wxFONTENCODING_SYSTEM )
         {
             convertEncoding = FALSE; // unknown encoding
@@ -1340,7 +1340,7 @@ wxFontEncoding wxLocale::GetSystemEncoding()
     wxString encname = GetSystemEncodingName();
     if ( !encname.empty() )
     {
-        wxFontEncoding enc = wxTheFontMapper->
+        wxFontEncoding enc = wxFontMapper::Get()->
             CharsetToEncoding(encname, FALSE /* not interactive */);
 
         // this should probably be considered as a bug in CharsetToEncoding():
diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp
index 1a5dbe119a..677ad2714d 100644
--- a/src/common/strconv.cpp
+++ b/src/common/strconv.cpp
@@ -791,7 +791,7 @@ public:
                                      enc(wxFONTENCODING_SYSTEM)
     {
         if (name)
-            enc = wxTheFontMapper->CharsetToEncoding(name, FALSE);
+            enc = wxFontMapper::Get()->CharsetToEncoding(name, FALSE);
 
         m_ok = m2w.Init(enc, wxFONTENCODING_UNICODE) &&
                w2m.Init(wxFONTENCODING_UNICODE, enc);
@@ -840,7 +840,7 @@ static wxCharacterSet *wxGetCharacterSet(const wxChar *name)
 {
     // check for the special case of ASCII charset
 #if wxUSE_FONTMAP
-    if ( wxTheFontMapper->CharsetToEncoding(name) == wxFONTENCODING_DEFAULT )
+    if ( wxFontMapper::Get()->CharsetToEncoding(name) == wxFONTENCODING_DEFAULT )
 #else // wxUSE_FONTMAP
     if ( !name )
 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
diff --git a/src/html/helpdata.cpp b/src/html/helpdata.cpp
index 312857dedf..44392854d3 100644
--- a/src/html/helpdata.cpp
+++ b/src/html/helpdata.cpp
@@ -618,7 +618,7 @@ bool wxHtmlHelpData::AddBook(const wxString& book)
 
         wxFontEncoding enc;
         if (charset == wxEmptyString) enc = wxFONTENCODING_SYSTEM;
-        else enc = wxTheFontMapper->CharsetToEncoding(charset);
+        else enc = wxFontMapper::Get()->CharsetToEncoding(charset);
         bool rtval = AddBookParam(*fi, enc,
                                   title, contents, index, start, fsys.GetPath());
         delete fi;
diff --git a/src/html/m_meta.cpp b/src/html/m_meta.cpp
index 2c707c6c82..9ad9eb7c4b 100644
--- a/src/html/m_meta.cpp
+++ b/src/html/m_meta.cpp
@@ -46,7 +46,7 @@ TAG_HANDLER_BEGIN(META, "META")
             if (content.Left(19) == _T("text/html; charset="))
             {
                 wxFontEncoding enc =
-                    wxTheFontMapper->CharsetToEncoding(content.Mid(19));
+                    wxFontMapper::Get()->CharsetToEncoding(content.Mid(19));
                 if (enc == wxFONTENCODING_SYSTEM) return FALSE;
                 if (enc == m_WParser->GetInputEncoding()) return FALSE;
 
diff --git a/src/html/winpars.cpp b/src/html/winpars.cpp
index 9d8209ddfb..877341fc05 100644
--- a/src/html/winpars.cpp
+++ b/src/html/winpars.cpp
@@ -390,21 +390,21 @@ void wxHtmlWinParser::SetInputEncoding(wxFontEncoding enc)
     bool availfix, availnorm;
 
     // exact match?
-    availnorm = wxTheFontMapper->IsEncodingAvailable(enc, m_FontFaceNormal);
-    availfix = wxTheFontMapper->IsEncodingAvailable(enc, m_FontFaceFixed);
+    availnorm = wxFontMapper::Get()->IsEncodingAvailable(enc, m_FontFaceNormal);
+    availfix = wxFontMapper::Get()->IsEncodingAvailable(enc, m_FontFaceFixed);
     if (availnorm && availfix)
         m_OutputEnc = enc;
 
     // alternatives?
-    else if (wxTheFontMapper->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, FALSE) &&
-             wxTheFontMapper->GetAltForEncoding(enc, &altfix, m_FontFaceFixed, FALSE) &&
+    else if (wxFontMapper::Get()->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, FALSE) &&
+             wxFontMapper::Get()->GetAltForEncoding(enc, &altfix, m_FontFaceFixed, FALSE) &&
              altnorm == altfix)
         m_OutputEnc = altnorm;
 
     // at least normal face?
     else if (availnorm)
         m_OutputEnc = enc;
-    else if (wxTheFontMapper->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, FALSE))
+    else if (wxFontMapper::Get()->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, FALSE))
         m_OutputEnc = altnorm;
 
     // okay, let convert to ISO_8859-1, available always
diff --git a/src/mac/carbon/fontenum.cpp b/src/mac/carbon/fontenum.cpp
index e1b1347c6d..4720cc4a75 100644
--- a/src/mac/carbon/fontenum.cpp
+++ b/src/mac/carbon/fontenum.cpp
@@ -89,7 +89,7 @@ bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
     wxNativeEncodingInfo info;
     if ( !wxGetNativeFontEncoding(encoding, &info) )
     {
-        if ( !wxTheFontMapper->GetAltForEncoding(encoding, &info) )
+        if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &info) )
         {
             // no such encodings at all
             return FALSE;
diff --git a/src/mac/fontenum.cpp b/src/mac/fontenum.cpp
index e1b1347c6d..4720cc4a75 100644
--- a/src/mac/fontenum.cpp
+++ b/src/mac/fontenum.cpp
@@ -89,7 +89,7 @@ bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
     wxNativeEncodingInfo info;
     if ( !wxGetNativeFontEncoding(encoding, &info) )
     {
-        if ( !wxTheFontMapper->GetAltForEncoding(encoding, &info) )
+        if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &info) )
         {
             // no such encodings at all
             return FALSE;
diff --git a/src/mgl/dc.cpp b/src/mgl/dc.cpp
index e38597f419..4a2a4909ec 100644
--- a/src/mgl/dc.cpp
+++ b/src/mgl/dc.cpp
@@ -759,7 +759,7 @@ bool wxDC::SelectMGLFont()
              !wxTestFontEncoding(nativeEnc) )
         {
 #if wxUSE_FONTMAP
-            if ( !wxTheFontMapper->GetAltForEncoding(encoding, &nativeEnc) )
+            if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &nativeEnc) )
 #endif
             {
                 nativeEnc.mglEncoding = MGL_ENCODING_ASCII;
diff --git a/src/msw/font.cpp b/src/msw/font.cpp
index 16993de878..25ff0295e3 100644
--- a/src/msw/font.cpp
+++ b/src/msw/font.cpp
@@ -523,7 +523,7 @@ void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding)
     if ( !wxGetNativeFontEncoding(encoding, &info) )
     {
 #if wxUSE_FONTMAP
-        if ( wxTheFontMapper->GetAltForEncoding(encoding, &info) )
+        if ( wxFontMapper::Get()->GetAltForEncoding(encoding, &info) )
         {
             if ( !info.facename.empty() )
             {
diff --git a/src/msw/fontenum.cpp b/src/msw/fontenum.cpp
index 80ce3c606e..553b574f7a 100644
--- a/src/msw/fontenum.cpp
+++ b/src/msw/fontenum.cpp
@@ -131,7 +131,7 @@ bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
         if ( !wxGetNativeFontEncoding(encoding, &info) )
         {
 #if wxUSE_FONTMAP
-            if ( !wxTheFontMapper->GetAltForEncoding(encoding, &info) )
+            if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &info) )
 #endif // wxUSE_FONTMAP
             {
                 // no such encodings at all
diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp
index 8c8e108650..117a19c12d 100644
--- a/src/msw/utils.cpp
+++ b/src/msw/utils.cpp
@@ -1592,7 +1592,7 @@ extern long wxCharsetToCodepage(const wxChar *name)
     if ( !name )
         return -1;
 
-    wxFontEncoding enc = wxTheFontMapper->CharsetToEncoding(name, FALSE);
+    wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(name, FALSE);
     if ( enc == wxFONTENCODING_SYSTEM )
         return -1;
 
diff --git a/src/os2/font.cpp b/src/os2/font.cpp
index c1839db1ca..443ec80ee8 100644
--- a/src/os2/font.cpp
+++ b/src/os2/font.cpp
@@ -702,7 +702,7 @@ void wxNativeFontInfo::SetEncoding(
                                  ))
     {
 #if wxUSE_FONTMAP
-        if (wxTheFontMapper->GetAltForEncoding( eEncoding
+        if (wxFontMapper::Get()->GetAltForEncoding( eEncoding
                                                ,&vInfo
                                               ))
         {
diff --git a/src/os2/fontenum.cpp b/src/os2/fontenum.cpp
index 476798911f..26a1043932 100644
--- a/src/os2/fontenum.cpp
+++ b/src/os2/fontenum.cpp
@@ -99,7 +99,7 @@ bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
     wxNativeEncodingInfo info;
     if ( !wxGetNativeFontEncoding(encoding, &info) )
     {
-        if ( !wxTheFontMapper->GetAltForEncoding(encoding, &info) )
+        if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &info) )
         {
             // no such encodings at all
             return FALSE;
diff --git a/src/os2/wx23.def b/src/os2/wx23.def
index faaea4fd63..c61844d060 100644
--- a/src/os2/wx23.def
+++ b/src/os2/wx23.def
@@ -2426,7 +2426,6 @@ EXPORTS
       GetEncodingName__12wxFontMapperF14wxFontEncoding
       ;wxFontMapper::~wxFontMapper()
       __dt__12wxFontMapperFv
-      wxTheFontMapper
       ;wxFontMapper::GetDefaultConfigPath()
       GetDefaultConfigPath__12wxFontMapperFv
       ;wxFontMapper::GetEncodingDescription(wxFontEncoding)
diff --git a/src/unix/fontenum.cpp b/src/unix/fontenum.cpp
index bc76c80086..fdeb46a105 100644
--- a/src/unix/fontenum.cpp
+++ b/src/unix/fontenum.cpp
@@ -79,7 +79,7 @@ static char **CreateFontList(wxChar spacing,
     if ( !wxTestFontEncoding(info) )
     {
         // ask font mapper for a replacement
-        (void)wxTheFontMapper->GetAltForEncoding(encoding, &info);
+        (void)wxFontMapper::Get()->GetAltForEncoding(encoding, &info);
     }
 #endif // wxUSE_FONTMAP
 
diff --git a/src/unix/fontutil.cpp b/src/unix/fontutil.cpp
index e161707732..9501ea5ee7 100644
--- a/src/unix/fontutil.cpp
+++ b/src/unix/fontutil.cpp
@@ -425,7 +425,7 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
              !wxTestFontEncoding(info) )
         {
 #if wxUSE_FONTMAP
-            if ( !wxTheFontMapper->GetAltForEncoding(encoding, &info) )
+            if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &info) )
 #endif // wxUSE_FONTMAP
             {
                 // unspported encoding - replace it with the default
-- 
2.50.0

