added wxFontMapper::Get/Set

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14969 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2002-04-06 15:04:27 +00:00
parent 5a224901b8
commit 142b3bc26a
25 changed files with 104 additions and 63 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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}}

View File

@ -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,

View File

@ -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

View File

@ -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());
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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
// ----------------------------------------------------------------------------

View File

@ -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():

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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() )
{

View File

@ -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

View File

@ -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;

View File

@ -702,7 +702,7 @@ void wxNativeFontInfo::SetEncoding(
))
{
#if wxUSE_FONTMAP
if (wxTheFontMapper->GetAltForEncoding( eEncoding
if (wxFontMapper::Get()->GetAltForEncoding( eEncoding
,&vInfo
))
{

View File

@ -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;

View File

@ -2426,7 +2426,6 @@ EXPORTS
GetEncodingName__12wxFontMapperF14wxFontEncoding
;wxFontMapper::~wxFontMapper()
__dt__12wxFontMapperFv
wxTheFontMapper
;wxFontMapper::GetDefaultConfigPath()
GetDefaultConfigPath__12wxFontMapperFv
;wxFontMapper::GetEncodingDescription(wxFontEncoding)

View File

@ -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

View File

@ -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