1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/fmapbase.cpp
3 // Purpose: wxFontMapperBase class implementation
4 // Author: Vadim Zeitlin
6 // Created: 21.06.2003 (extracted from common/fontmap.cpp)
8 // Copyright: (c) 1999-2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/module.h"
34 #include "wx/wxcrtvararg.h"
37 #if defined(__WXMSW__)
38 #include "wx/msw/private.h" // includes windows.h for LOGFONT
39 #include "wx/msw/winundef.h"
42 #include "wx/fontmap.h"
43 #include "wx/fmappriv.h"
45 #include "wx/apptrait.h"
47 // wxMemoryConfig uses wxFileConfig
48 #if wxUSE_CONFIG && wxUSE_FILECONFIG
49 #include "wx/config.h"
50 #include "wx/memconf.h"
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 // encodings supported by GetEncodingDescription
58 static wxFontEncoding gs_encodings
[] =
60 wxFONTENCODING_ISO8859_1
,
61 wxFONTENCODING_ISO8859_2
,
62 wxFONTENCODING_ISO8859_3
,
63 wxFONTENCODING_ISO8859_4
,
64 wxFONTENCODING_ISO8859_5
,
65 wxFONTENCODING_ISO8859_6
,
66 wxFONTENCODING_ISO8859_7
,
67 wxFONTENCODING_ISO8859_8
,
68 wxFONTENCODING_ISO8859_9
,
69 wxFONTENCODING_ISO8859_10
,
70 wxFONTENCODING_ISO8859_11
,
71 wxFONTENCODING_ISO8859_12
,
72 wxFONTENCODING_ISO8859_13
,
73 wxFONTENCODING_ISO8859_14
,
74 wxFONTENCODING_ISO8859_15
,
76 wxFONTENCODING_KOI8_U
,
82 wxFONTENCODING_CP1250
,
83 wxFONTENCODING_CP1251
,
84 wxFONTENCODING_CP1252
,
85 wxFONTENCODING_CP1253
,
86 wxFONTENCODING_CP1254
,
87 wxFONTENCODING_CP1255
,
88 wxFONTENCODING_CP1256
,
89 wxFONTENCODING_CP1257
,
93 wxFONTENCODING_UTF16BE
,
94 wxFONTENCODING_UTF16LE
,
95 wxFONTENCODING_UTF32BE
,
96 wxFONTENCODING_UTF32LE
,
97 wxFONTENCODING_EUC_JP
,
98 wxFONTENCODING_DEFAULT
,
100 wxFONTENCODING_SHIFT_JIS
,
101 wxFONTENCODING_GB2312
,
102 wxFONTENCODING_ISO2022_JP
,
105 // the descriptions for them
106 static const char* gs_encodingDescs
[] =
108 wxTRANSLATE( "Western European (ISO-8859-1)" ),
109 wxTRANSLATE( "Central European (ISO-8859-2)" ),
110 wxTRANSLATE( "Esperanto (ISO-8859-3)" ),
111 wxTRANSLATE( "Baltic (old) (ISO-8859-4)" ),
112 wxTRANSLATE( "Cyrillic (ISO-8859-5)" ),
113 wxTRANSLATE( "Arabic (ISO-8859-6)" ),
114 wxTRANSLATE( "Greek (ISO-8859-7)" ),
115 wxTRANSLATE( "Hebrew (ISO-8859-8)" ),
116 wxTRANSLATE( "Turkish (ISO-8859-9)" ),
117 wxTRANSLATE( "Nordic (ISO-8859-10)" ),
118 wxTRANSLATE( "Thai (ISO-8859-11)" ),
119 wxTRANSLATE( "Indian (ISO-8859-12)" ),
120 wxTRANSLATE( "Baltic (ISO-8859-13)" ),
121 wxTRANSLATE( "Celtic (ISO-8859-14)" ),
122 wxTRANSLATE( "Western European with Euro (ISO-8859-15)" ),
123 wxTRANSLATE( "KOI8-R" ),
124 wxTRANSLATE( "KOI8-U" ),
125 wxTRANSLATE( "Windows Thai (CP 874)" ),
126 wxTRANSLATE( "Windows Japanese (CP 932)" ),
127 wxTRANSLATE( "Windows Chinese Simplified (CP 936)" ),
128 wxTRANSLATE( "Windows Korean (CP 949)" ),
129 wxTRANSLATE( "Windows Chinese Traditional (CP 950)" ),
130 wxTRANSLATE( "Windows Central European (CP 1250)" ),
131 wxTRANSLATE( "Windows Cyrillic (CP 1251)" ),
132 wxTRANSLATE( "Windows Western European (CP 1252)" ),
133 wxTRANSLATE( "Windows Greek (CP 1253)" ),
134 wxTRANSLATE( "Windows Turkish (CP 1254)" ),
135 wxTRANSLATE( "Windows Hebrew (CP 1255)" ),
136 wxTRANSLATE( "Windows Arabic (CP 1256)" ),
137 wxTRANSLATE( "Windows Baltic (CP 1257)" ),
138 wxTRANSLATE( "Windows/DOS OEM (CP 437)" ),
139 wxTRANSLATE( "Unicode 7 bit (UTF-7)" ),
140 wxTRANSLATE( "Unicode 8 bit (UTF-8)" ),
141 #ifdef WORDS_BIGENDIAN
142 wxTRANSLATE( "Unicode 16 bit (UTF-16)" ),
143 wxTRANSLATE( "Unicode 16 bit Little Endian (UTF-16LE)" ),
144 wxTRANSLATE( "Unicode 32 bit (UTF-32)" ),
145 wxTRANSLATE( "Unicode 32 bit Little Endian (UTF-32LE)" ),
146 #else // WORDS_BIGENDIAN
147 wxTRANSLATE( "Unicode 16 bit Big Endian (UTF-16BE)" ),
148 wxTRANSLATE( "Unicode 16 bit (UTF-16)" ),
149 wxTRANSLATE( "Unicode 32 bit Big Endian (UTF-32BE)" ),
150 wxTRANSLATE( "Unicode 32 bit (UTF-32)" ),
151 #endif // WORDS_BIGENDIAN
152 wxTRANSLATE( "Extended Unix Codepage for Japanese (EUC-JP)" ),
153 wxTRANSLATE( "US-ASCII" ),
154 wxTRANSLATE( "BIG5" ),
155 wxTRANSLATE( "SHIFT-JIS" ),
156 wxTRANSLATE( "GB-2312" ),
157 wxTRANSLATE( "ISO-2022-JP" ),
160 // and the internal names (these are not translated on purpose!)
161 static const wxChar
* gs_encodingNames
[WXSIZEOF(gs_encodingDescs
)][9] =
163 // names from the columns correspond to these OS:
164 // Linux Solaris and IRIX HP-UX AIX
165 { _T("ISO-8859-1"), _T("ISO8859-1"), _T("iso88591"), _T("8859-1"), wxT("iso_8859_1"), NULL
},
166 { _T("ISO-8859-2"), _T("ISO8859-2"), _T("iso88592"), _T("8859-2"), NULL
},
167 { _T("ISO-8859-3"), _T("ISO8859-3"), _T("iso88593"), _T("8859-3"), NULL
},
168 { _T("ISO-8859-4"), _T("ISO8859-4"), _T("iso88594"), _T("8859-4"), NULL
},
169 { _T("ISO-8859-5"), _T("ISO8859-5"), _T("iso88595"), _T("8859-5"), NULL
},
170 { _T("ISO-8859-6"), _T("ISO8859-6"), _T("iso88596"), _T("8859-6"), NULL
},
171 { _T("ISO-8859-7"), _T("ISO8859-7"), _T("iso88597"), _T("8859-7"), NULL
},
172 { _T("ISO-8859-8"), _T("ISO8859-8"), _T("iso88598"), _T("8859-8"), NULL
},
173 { _T("ISO-8859-9"), _T("ISO8859-9"), _T("iso88599"), _T("8859-9"), NULL
},
174 { _T("ISO-8859-10"), _T("ISO8859-10"), _T("iso885910"), _T("8859-10"), NULL
},
175 { _T("ISO-8859-11"), _T("ISO8859-11"), _T("iso885911"), _T("8859-11"), NULL
},
176 { _T("ISO-8859-12"), _T("ISO8859-12"), _T("iso885912"), _T("8859-12"), NULL
},
177 { _T("ISO-8859-13"), _T("ISO8859-13"), _T("iso885913"), _T("8859-13"), NULL
},
178 { _T("ISO-8859-14"), _T("ISO8859-14"), _T("iso885914"), _T("8859-14"), NULL
},
179 { _T("ISO-8859-15"), _T("ISO8859-15"), _T("iso885915"), _T("8859-15"), NULL
},
181 // although koi8-ru is not strictly speaking the same as koi8-r,
182 // they are similar enough to make mapping it to koi8 better than
183 // not recognizing it at all
184 { wxT( "KOI8-R" ), wxT( "KOI8-RU" ), NULL
},
185 { wxT( "KOI8-U" ), NULL
},
187 { wxT( "WINDOWS-874" ), wxT( "CP-874" ), wxT( "MS-874" ), wxT( "IBM-874" ), NULL
},
188 { wxT( "WINDOWS-932" ), wxT( "CP-932" ), wxT( "MS-932" ), wxT( "IBM-932" ), NULL
},
189 { wxT( "WINDOWS-936" ), wxT( "CP-936" ), wxT( "MS-936" ), wxT( "IBM-936" ), NULL
},
190 { wxT( "WINDOWS-949" ), wxT( "CP-949" ), wxT( "MS-949" ), wxT( "IBM-949" ), wxT( "EUC-KR" ), wxT( "eucKR" ), wxT( "euc_kr" ), NULL
},
191 { wxT( "WINDOWS-950" ), wxT( "CP-950" ), wxT( "MS-950" ), wxT( "IBM-950" ), NULL
},
192 { wxT( "WINDOWS-1250" ),wxT( "CP-1250" ),wxT( "MS-1250" ),wxT( "IBM-1250" ),NULL
},
193 { wxT( "WINDOWS-1251" ),wxT( "CP-1251" ),wxT( "MS-1251" ),wxT( "IBM-1251" ),NULL
},
194 { wxT( "WINDOWS-1252" ),wxT( "CP-1252" ),wxT( "MS-1252" ),wxT( "IBM-1252" ),NULL
},
195 { wxT( "WINDOWS-1253" ),wxT( "CP-1253" ),wxT( "MS-1253" ),wxT( "IBM-1253" ),NULL
},
196 { wxT( "WINDOWS-1254" ),wxT( "CP-1254" ),wxT( "MS-1254" ),wxT( "IBM-1254" ),NULL
},
197 { wxT( "WINDOWS-1255" ),wxT( "CP-1255" ),wxT( "MS-1255" ),wxT( "IBM-1255" ),NULL
},
198 { wxT( "WINDOWS-1256" ),wxT( "CP-1256" ),wxT( "MS-1256" ),wxT( "IBM-1256" ),NULL
},
199 { wxT( "WINDOWS-1257" ),wxT( "CP-1257" ),wxT( "MS-1257" ),wxT( "IBM-1257" ),NULL
},
200 { wxT( "WINDOWS-437" ), wxT( "CP-437" ), wxT( "MS-437" ), wxT( "IBM-437" ), NULL
},
202 { wxT( "UTF-7" ), NULL
},
203 { wxT( "UTF-8" ), NULL
},
204 #ifdef WORDS_BIGENDIAN
205 { wxT( "UTF-16BE" ), wxT("UCS-2BE"), wxT( "UTF-16" ), wxT("UCS-2"), NULL
},
206 { wxT( "UTF-16LE" ), wxT("UCS-2LE"), NULL
},
207 { wxT( "UTF-32BE" ), wxT( "UCS-4BE" ), wxT( "UTF-32" ), wxT( "UCS-4" ), NULL
},
208 { wxT( "UTF-32LE" ), wxT( "UCS-4LE" ), NULL
},
209 #else // WORDS_BIGENDIAN
210 { wxT( "UTF-16BE" ), wxT("UCS-2BE"), NULL
},
211 { wxT( "UTF-16LE" ), wxT("UCS-2LE"), wxT( "UTF-16" ), wxT("UCS-2"), NULL
},
212 { wxT( "UTF-32BE" ), wxT( "UCS-4BE" ), NULL
},
213 { wxT( "UTF-32LE" ), wxT( "UCS-4LE" ), wxT( "UTF-32" ), wxT( "UCS-4" ), NULL
},
214 #endif // WORDS_BIGENDIAN
216 { wxT( "EUC-JP" ), wxT( "eucJP" ), wxT( "euc_jp" ), wxT( "IBM-eucJP" ), NULL
},
218 // 646 is for Solaris, roman8 -- for HP-UX
219 { wxT( "US-ASCII" ), wxT( "ASCII" ), wxT("C"), wxT("POSIX"), wxT("ANSI_X3.4-1968"),
220 wxT("646"), wxT("roman8"), wxT( "" ), NULL
},
222 { wxT( "BIG5" ), wxT("big5"), NULL
},
223 { wxT( "SJIS" ), wxT( "SHIFT-JIS" ), wxT( "SHIFT_JIS" ), NULL
},
224 { wxT( "GB2312" ), NULL
},
225 { wxT( "ISO-2022-JP" ), NULL
},
228 wxCOMPILE_TIME_ASSERT( WXSIZEOF(gs_encodingDescs
) == WXSIZEOF(gs_encodings
), EncodingsArraysNotInSync
);
229 wxCOMPILE_TIME_ASSERT( WXSIZEOF(gs_encodingNames
) == WXSIZEOF(gs_encodings
), EncodingsArraysNotInSync
);
231 // ----------------------------------------------------------------------------
233 // ----------------------------------------------------------------------------
235 // clean up the font mapper object
236 class wxFontMapperModule
: public wxModule
239 wxFontMapperModule() : wxModule() { }
241 virtual bool OnInit()
243 // a dummy wxFontMapperBase object could have been created during the
244 // program startup before wxApp was created, we have to delete it to
245 // allow creating the real font mapper next time it is needed now that
246 // we can create it (when the modules are initialized, wxApp object
248 wxFontMapperBase
*fm
= wxFontMapperBase::Get();
249 if ( fm
&& fm
->IsDummy() )
250 wxFontMapperBase::Reset();
255 virtual void OnExit()
257 wxFontMapperBase::Reset();
260 DECLARE_DYNAMIC_CLASS(wxFontMapperModule
)
263 IMPLEMENT_DYNAMIC_CLASS(wxFontMapperModule
, wxModule
)
266 // ============================================================================
267 // wxFontMapperBase implementation
268 // ============================================================================
270 wxFontMapper
*wxFontMapperBase::sm_instance
= NULL
;
272 // ----------------------------------------------------------------------------
274 // ----------------------------------------------------------------------------
276 wxFontMapperBase::wxFontMapperBase()
278 #if wxUSE_CONFIG && wxUSE_FILECONFIG
279 m_configDummy
= NULL
;
280 #endif // wxUSE_CONFIG
283 wxFontMapperBase::~wxFontMapperBase()
285 #if wxUSE_CONFIG && wxUSE_FILECONFIG
287 delete m_configDummy
;
288 #endif // wxUSE_CONFIG
292 wxFontMapperBase
*wxFontMapperBase::Get()
296 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
299 sm_instance
= traits
->CreateFontMapper();
301 wxASSERT_MSG( sm_instance
,
302 _T("wxAppTraits::CreateFontMapper() failed") );
307 // last resort: we must create something because the existing code
308 // relies on always having a valid font mapper object
309 sm_instance
= (wxFontMapper
*)new wxFontMapperBase
;
313 return (wxFontMapperBase
*)sm_instance
;
317 wxFontMapper
*wxFontMapperBase::Set(wxFontMapper
*mapper
)
319 wxFontMapper
*old
= sm_instance
;
320 sm_instance
= mapper
;
325 void wxFontMapperBase::Reset()
329 // we need a cast as wxFontMapper is not fully declared here and so the
330 // compiler can't know that it derives from wxFontMapperBase (but
331 // run-time behaviour will be correct because the dtor is virtual)
332 delete (wxFontMapperBase
*)sm_instance
;
337 #if wxUSE_CONFIG && wxUSE_FILECONFIG
339 // ----------------------------------------------------------------------------
340 // config usage customisation
341 // ----------------------------------------------------------------------------
344 static wxString
gs_defaultConfigPath(FONTMAPPER_ROOT_PATH
);
347 const wxString
& wxFontMapperBase::GetDefaultConfigPath()
349 // NB: we return const wxString& and not wxString for compatibility
350 // with 2.8 that returned const wxChar*
351 return gs_defaultConfigPath
;
354 void wxFontMapperBase::SetConfigPath(const wxString
& prefix
)
356 wxCHECK_RET( !prefix
.empty() && prefix
[0] == wxCONFIG_PATH_SEPARATOR
,
357 wxT("an absolute path should be given to wxFontMapper::SetConfigPath()") );
359 m_configRootPath
= prefix
;
362 // ----------------------------------------------------------------------------
363 // get config object and path for it
364 // ----------------------------------------------------------------------------
366 wxConfigBase
*wxFontMapperBase::GetConfig()
368 wxConfigBase
*config
= wxConfig::Get(false);
370 // If there is no global configuration, use an internal memory configuration
373 if ( !m_configDummy
)
374 m_configDummy
= new wxMemoryConfig
;
375 config
= m_configDummy
;
377 // FIXME: ideally, we should add keys from dummy config to a real one later,
378 // but it is a low-priority task because typical wxWin application
379 // either doesn't use wxConfig at all or creates wxConfig object in
380 // wxApp::OnInit(), before any real interaction with the user takes
387 const wxString
& wxFontMapperBase::GetConfigPath()
389 if ( !m_configRootPath
)
392 m_configRootPath
= GetDefaultConfigPath();
395 return m_configRootPath
;
398 // ----------------------------------------------------------------------------
400 // ----------------------------------------------------------------------------
402 bool wxFontMapperBase::ChangePath(const wxString
& pathNew
, wxString
*pathOld
)
404 wxConfigBase
*config
= GetConfig();
408 *pathOld
= config
->GetPath();
410 wxString path
= GetConfigPath();
411 if ( path
.empty() || path
.Last() != wxCONFIG_PATH_SEPARATOR
)
413 path
+= wxCONFIG_PATH_SEPARATOR
;
416 wxASSERT_MSG( !pathNew
|| (pathNew
[0] != wxCONFIG_PATH_SEPARATOR
),
417 wxT("should be a relative path") );
421 config
->SetPath(path
);
426 void wxFontMapperBase::RestorePath(const wxString
& pathOld
)
428 GetConfig()->SetPath(pathOld
);
433 // ----------------------------------------------------------------------------
434 // charset/encoding correspondence
435 // ----------------------------------------------------------------------------
438 wxFontMapperBase::CharsetToEncoding(const wxString
& charset
,
439 bool WXUNUSED(interactive
))
441 int enc
= NonInteractiveCharsetToEncoding(charset
);
442 if ( enc
== wxFONTENCODING_UNKNOWN
)
444 // we should return wxFONTENCODING_SYSTEM from here for unknown
446 enc
= wxFONTENCODING_SYSTEM
;
449 return (wxFontEncoding
)enc
;
453 wxFontMapperBase::NonInteractiveCharsetToEncoding(const wxString
& charset
)
455 wxFontEncoding encoding
= wxFONTENCODING_SYSTEM
;
457 // we're going to modify it, make a copy
458 wxString cs
= charset
;
460 #if wxUSE_CONFIG && wxUSE_FILECONFIG
461 // first try the user-defined settings
462 wxFontMapperPathChanger
path(this, FONTMAPPER_CHARSET_PATH
);
465 wxConfigBase
*config
= GetConfig();
467 // do we have an encoding for this charset?
468 long value
= config
->Read(charset
, -1l);
471 if ( value
== wxFONTENCODING_UNKNOWN
)
473 // don't try to find it, in particular don't ask the user
477 if ( value
>= 0 && value
<= wxFONTENCODING_MAX
)
479 encoding
= (wxFontEncoding
)value
;
483 wxLogDebug(wxT("corrupted config data: invalid encoding %ld for charset '%s' ignored"),
484 value
, charset
.c_str());
488 if ( encoding
== wxFONTENCODING_SYSTEM
)
490 // may be we have an alias?
491 config
->SetPath(FONTMAPPER_CHARSET_ALIAS_PATH
);
493 wxString alias
= config
->Read(charset
);
494 if ( !alias
.empty() )
496 // yes, we do - use it instead
501 #endif // wxUSE_CONFIG
503 // if didn't find it there, try to recognize it ourselves
504 if ( encoding
== wxFONTENCODING_SYSTEM
)
510 // discard the optional quotes
513 if ( cs
[0u] == _T('"') && cs
.Last() == _T('"') )
515 cs
= wxString(cs
.c_str(), cs
.length() - 1);
519 // check for known encoding name
520 const wxFontEncoding e
= GetEncodingFromName(cs
);
521 if ( e
!= wxFONTENCODING_MAX
)
524 // deal with general encoding names of the form FOO-xxx
527 if ( cs
.Left(3) == wxT("ISO") )
529 // the dash is optional (or, to be exact, it is not, but many
530 // broken programs "forget" it in the output they generate)
531 const wxChar
*p
= cs
.c_str() + 3;
532 if ( *p
== wxT('-') )
536 if ( wxSscanf(p
, wxT("8859-%u"), &value
) == 1 )
538 // make it 0 based and check that it is strictly positive in
539 // the process (no such thing as iso8859-0 encoding)
540 if ( (value
-- > 0) &&
541 (value
< wxFONTENCODING_ISO8859_MAX
-
542 wxFONTENCODING_ISO8859_1
) )
544 // it's a valid ISO8859 encoding
545 value
+= wxFONTENCODING_ISO8859_1
;
546 encoding
= (wxFontEncoding
)value
;
550 else if ( cs
.Left(4) == wxT("8859") )
552 const wxChar
*p
= cs
.c_str();
555 if ( wxSscanf(p
, wxT("8859-%u"), &value
) == 1 )
557 // make it 0 based and check that it is strictly positive in
558 // the process (no such thing as iso8859-0 encoding)
559 if ( (value
-- > 0) &&
560 (value
< wxFONTENCODING_ISO8859_MAX
-
561 wxFONTENCODING_ISO8859_1
) )
563 // it's a valid ISO8859 encoding
564 value
+= wxFONTENCODING_ISO8859_1
;
565 encoding
= (wxFontEncoding
)value
;
569 else // check for Windows charsets
572 if ( cs
.Left(7) == wxT("WINDOWS") )
576 else if ( cs
.Left(2) == wxT("CP") )
580 else // not a Windows encoding
587 const wxChar
*p
= cs
.c_str() + len
;
588 if ( *p
== wxT('-') )
592 if ( wxSscanf(p
, wxT("%u"), &value
) == 1 )
597 if ( value
< wxFONTENCODING_CP12_MAX
-
598 wxFONTENCODING_CP1250
)
600 // a valid Windows code page
601 value
+= wxFONTENCODING_CP1250
;
602 encoding
= (wxFontEncoding
)value
;
609 encoding
= wxFONTENCODING_CP866
;
613 encoding
= wxFONTENCODING_CP874
;
617 encoding
= wxFONTENCODING_CP932
;
621 encoding
= wxFONTENCODING_CP936
;
625 encoding
= wxFONTENCODING_CP949
;
629 encoding
= wxFONTENCODING_CP950
;
642 size_t wxFontMapperBase::GetSupportedEncodingsCount()
644 return WXSIZEOF(gs_encodings
);
648 wxFontEncoding
wxFontMapperBase::GetEncoding(size_t n
)
650 wxCHECK_MSG( n
< WXSIZEOF(gs_encodings
), wxFONTENCODING_SYSTEM
,
651 _T("wxFontMapper::GetEncoding(): invalid index") );
653 return gs_encodings
[n
];
657 wxString
wxFontMapperBase::GetEncodingDescription(wxFontEncoding encoding
)
659 if ( encoding
== wxFONTENCODING_DEFAULT
)
661 return _("Default encoding");
664 const size_t count
= WXSIZEOF(gs_encodingDescs
);
666 for ( size_t i
= 0; i
< count
; i
++ )
668 if ( gs_encodings
[i
] == encoding
)
670 return wxGetTranslation(gs_encodingDescs
[i
]);
675 str
.Printf(_("Unknown encoding (%d)"), encoding
);
681 wxString
wxFontMapperBase::GetEncodingName(wxFontEncoding encoding
)
683 if ( encoding
== wxFONTENCODING_DEFAULT
)
688 const size_t count
= WXSIZEOF(gs_encodingNames
);
690 for ( size_t i
= 0; i
< count
; i
++ )
692 if ( gs_encodings
[i
] == encoding
)
694 return gs_encodingNames
[i
][0];
699 str
.Printf(_("unknown-%d"), encoding
);
705 const wxChar
** wxFontMapperBase::GetAllEncodingNames(wxFontEncoding encoding
)
707 static const wxChar
* dummy
[] = { NULL
};
709 for ( size_t i
= 0; i
< WXSIZEOF(gs_encodingNames
); i
++ )
711 if ( gs_encodings
[i
] == encoding
)
713 return gs_encodingNames
[i
];
721 wxFontEncoding
wxFontMapperBase::GetEncodingFromName(const wxString
& name
)
723 const size_t count
= WXSIZEOF(gs_encodingNames
);
725 // many charsets use hyphens in their names but some systems use the
726 // same names without hyphens (e.g. "UTF-8" and "UTF8" are both common)
727 // so to avoid bloating gs_encodingNames array too much recognize both
728 // versions with and without hyphens here
729 wxString
nameNoHyphens(name
);
730 if ( !nameNoHyphens
.Replace(_T("-"), _T("")) )
732 // no replacement has been done, no need to compare twice
733 nameNoHyphens
.clear();
737 for ( size_t i
= 0; i
< count
; i
++ )
739 for ( const wxChar
** encName
= gs_encodingNames
[i
]; *encName
; ++encName
)
741 if ( name
.CmpNoCase(*encName
) == 0 ||
742 (!nameNoHyphens
.empty() &&
743 nameNoHyphens
.CmpNoCase(*encName
) == 0) )
745 return gs_encodings
[i
];
750 return wxFONTENCODING_MAX
;
753 #endif // wxUSE_FONTMAP