compate charset names case-insensitively in GetEncodingFromName()
[wxWidgets.git] / src / common / fmapbase.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/fmapbase.cpp
3 // Purpose: wxFontMapperBase class implementation
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 21.06.2003 (extracted from common/fontmap.cpp)
7 // RCS-ID: $Id$
8 // Copyright: (c) 1999-2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_FONTMAP
28
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #include "wx/log.h"
32 #include "wx/intl.h"
33 #endif //WX_PRECOMP
34
35 #if defined(__WXMSW__)
36 #include "wx/msw/private.h" // includes windows.h for LOGFONT
37 #include "wx/msw/winundef.h"
38 #endif
39
40 #include "wx/fontmap.h"
41 #include "wx/fmappriv.h"
42
43 #include "wx/apptrait.h"
44 #include "wx/module.h"
45
46 // wxMemoryConfig uses wxFileConfig
47 #if wxUSE_CONFIG && wxUSE_FILECONFIG
48 #include "wx/config.h"
49 #include "wx/memconf.h"
50 #endif
51
52 // ----------------------------------------------------------------------------
53 // constants
54 // ----------------------------------------------------------------------------
55
56 // encodings supported by GetEncodingDescription
57 static wxFontEncoding gs_encodings[] =
58 {
59 wxFONTENCODING_ISO8859_1,
60 wxFONTENCODING_ISO8859_2,
61 wxFONTENCODING_ISO8859_3,
62 wxFONTENCODING_ISO8859_4,
63 wxFONTENCODING_ISO8859_5,
64 wxFONTENCODING_ISO8859_6,
65 wxFONTENCODING_ISO8859_7,
66 wxFONTENCODING_ISO8859_8,
67 wxFONTENCODING_ISO8859_9,
68 wxFONTENCODING_ISO8859_10,
69 wxFONTENCODING_ISO8859_11,
70 wxFONTENCODING_ISO8859_12,
71 wxFONTENCODING_ISO8859_13,
72 wxFONTENCODING_ISO8859_14,
73 wxFONTENCODING_ISO8859_15,
74 wxFONTENCODING_KOI8,
75 wxFONTENCODING_KOI8_U,
76 wxFONTENCODING_CP874,
77 wxFONTENCODING_CP932,
78 wxFONTENCODING_CP936,
79 wxFONTENCODING_CP949,
80 wxFONTENCODING_CP950,
81 wxFONTENCODING_CP1250,
82 wxFONTENCODING_CP1251,
83 wxFONTENCODING_CP1252,
84 wxFONTENCODING_CP1253,
85 wxFONTENCODING_CP1254,
86 wxFONTENCODING_CP1255,
87 wxFONTENCODING_CP1256,
88 wxFONTENCODING_CP1257,
89 wxFONTENCODING_CP437,
90 wxFONTENCODING_UTF7,
91 wxFONTENCODING_UTF8,
92 wxFONTENCODING_UTF16,
93 wxFONTENCODING_UTF16BE,
94 wxFONTENCODING_UTF16LE,
95 wxFONTENCODING_UTF32,
96 wxFONTENCODING_UTF32BE,
97 wxFONTENCODING_UTF32LE,
98 wxFONTENCODING_EUC_JP,
99 wxFONTENCODING_DEFAULT,
100 wxFONTENCODING_BIG5,
101 wxFONTENCODING_SHIFT_JIS,
102 wxFONTENCODING_GB2312,
103 };
104
105 // the descriptions for them
106 static const wxChar* gs_encodingDescs[] =
107 {
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 wxTRANSLATE( "Unicode 16 bit (UTF-16)" ),
142 wxTRANSLATE( "Unicode 16 bit Big Endian (UTF-16BE)" ),
143 wxTRANSLATE( "Unicode 16 bit Little Endian (UTF-16LE)" ),
144 wxTRANSLATE( "Unicode 32 bit (UTF-32)" ),
145 wxTRANSLATE( "Unicode 32 bit Big Endian (UTF-32BE)" ),
146 wxTRANSLATE( "Unicode 32 bit Little Endian (UTF-32LE)" ),
147 wxTRANSLATE( "Extended Unix Codepage for Japanese (EUC-JP)" ),
148 wxTRANSLATE( "US-ASCII" ),
149 wxTRANSLATE( "BIG5" ),
150 wxTRANSLATE( "SHIFT-JIS" ),
151 wxTRANSLATE( "GB-2312" ),
152 };
153
154 // and the internal names (these are not translated on purpose!)
155 static const wxChar* gs_encodingNames[WXSIZEOF(gs_encodingDescs)][7] =
156 {
157 { wxT( "iso-8859-1" ), NULL },
158 { wxT( "iso-8859-2" ), NULL },
159 { wxT( "iso-8859-3" ), NULL },
160 { wxT( "iso-8859-4" ), NULL },
161 { wxT( "iso-8859-5" ), NULL },
162 { wxT( "iso-8859-6" ), NULL },
163 { wxT( "iso-8859-7" ), NULL },
164 { wxT( "iso-8859-8" ), NULL },
165 { wxT( "iso-8859-9" ), NULL },
166 { wxT( "iso-8859-10" ), NULL },
167 { wxT( "iso-8859-11" ), NULL },
168 { wxT( "iso-8859-12" ), NULL },
169 { wxT( "iso-8859-13" ), NULL },
170 { wxT( "iso-8859-14" ), NULL },
171 { wxT( "iso-8859-15" ), NULL },
172 // although koi8-ru is not strictly speaking the same as koi8-r,
173 // they are similar enough to make mapping it to koi8 better than
174 // not recognizing it at all
175 { wxT( "koi8-r" ), wxT( "koi8-ru" ), NULL },
176 { wxT( "koi8-u" ), NULL },
177 { wxT( "windows-874" ), NULL },
178 { wxT( "windows-932" ), NULL },
179 { wxT( "windows-936" ), NULL },
180 { wxT( "windows-949" ), wxT( "euc-kr" ),
181 wxT( "euckr" ), wxT( "euc_kr" ), NULL },
182 { wxT( "windows-950" ), NULL },
183 { wxT( "windows-1250" ), NULL },
184 { wxT( "windows-1251" ), NULL },
185 { wxT( "windows-1252" ), NULL },
186 { wxT( "windows-1253" ), NULL },
187 { wxT( "windows-1254" ), NULL },
188 { wxT( "windows-1255" ), NULL },
189 { wxT( "windows-1256" ), NULL },
190 { wxT( "windows-1257" ), NULL },
191 { wxT( "windows-437" ), NULL },
192 { wxT( "UTF-7" ), NULL },
193 { wxT( "UTF-8" ), NULL },
194 { wxT( "UTF-16" ), NULL },
195 { wxT( "UTF-16be" ), NULL },
196 { wxT( "UTF-16le" ), NULL },
197 { wxT( "UTF-32" ), wxT( "UCS-4" ), NULL },
198 { wxT( "UTF-32be" ), wxT( "UCS-4be" ), NULL },
199 { wxT( "UTF-32le" ), wxT( "UCS-4le" ), NULL },
200 { wxT( "euc-jp" ), wxT( "eucJP" ), wxT( "euc_jp" ), wxT( "IBM-eucJP" ), NULL },
201 { wxT( "us-ascii" ), wxT( "ascii" ), wxT("ANSI_X3.4-1968"),
202 #ifdef __SOLARIS__
203 wxT("646"),
204 #endif
205 #ifdef __HPUX__
206 wxT("roman8"),
207 #endif
208 wxT( "" ), NULL },
209 { wxT( "big5" ), NULL },
210 { wxT( "shift-jis" ), wxT( "shift_jis" ), wxT( "sjis" ), NULL },
211 { wxT( "gb2312" ), NULL },
212 };
213
214 wxCOMPILE_TIME_ASSERT( WXSIZEOF(gs_encodingDescs) == WXSIZEOF(gs_encodings), EncodingsArraysNotInSync );
215 wxCOMPILE_TIME_ASSERT( WXSIZEOF(gs_encodingNames) == WXSIZEOF(gs_encodings), EncodingsArraysNotInSync );
216
217 // ----------------------------------------------------------------------------
218 // private classes
219 // ----------------------------------------------------------------------------
220
221 // clean up the font mapper object
222 class wxFontMapperModule : public wxModule
223 {
224 public:
225 wxFontMapperModule() : wxModule() { }
226 virtual bool OnInit() { return true; }
227 virtual void OnExit() { delete (wxFontMapperBase*)wxFontMapperBase::Set(NULL); }
228
229 DECLARE_DYNAMIC_CLASS(wxFontMapperModule)
230 };
231
232 IMPLEMENT_DYNAMIC_CLASS(wxFontMapperModule, wxModule)
233
234
235 // ============================================================================
236 // wxFontMapperBase implementation
237 // ============================================================================
238
239 wxFontMapper *wxFontMapperBase::sm_instance = NULL;
240
241 // ----------------------------------------------------------------------------
242 // ctor and dtor
243 // ----------------------------------------------------------------------------
244
245 wxFontMapperBase::wxFontMapperBase()
246 {
247 #if wxUSE_CONFIG && wxUSE_FILECONFIG
248 m_config = NULL;
249 m_configIsDummy = false;
250 #endif // wxUSE_CONFIG
251 }
252
253 wxFontMapperBase::~wxFontMapperBase()
254 {
255 #if wxUSE_CONFIG && wxUSE_FILECONFIG
256 if ( m_configIsDummy )
257 delete m_config;
258 #endif // wxUSE_CONFIG
259 }
260
261 bool wxFontMapperBase::IsWxFontMapper()
262 { return false; }
263
264 /* static */
265 wxFontMapperBase *wxFontMapperBase::Get()
266 {
267 if ( !sm_instance )
268 {
269 wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
270 if ( traits )
271 {
272 sm_instance = traits->CreateFontMapper();
273
274 wxASSERT_MSG( sm_instance,
275 _T("wxAppTraits::CreateFontMapper() failed") );
276 }
277
278 if ( !sm_instance )
279 {
280 // last resort: we must create something because the existing code
281 // relies on always having a valid font mapper object
282 sm_instance = (wxFontMapper *)new wxFontMapperBase;
283 }
284 }
285
286 return (wxFontMapperBase*)sm_instance;
287 }
288
289 /* static */
290 wxFontMapper *wxFontMapperBase::Set(wxFontMapper *mapper)
291 {
292 wxFontMapper *old = sm_instance;
293 sm_instance = mapper;
294 return old;
295 }
296
297 #if wxUSE_CONFIG && wxUSE_FILECONFIG
298
299 // ----------------------------------------------------------------------------
300 // config usage customisation
301 // ----------------------------------------------------------------------------
302
303 /* static */
304 const wxChar *wxFontMapperBase::GetDefaultConfigPath()
305 {
306 return FONTMAPPER_ROOT_PATH;
307 }
308
309 void wxFontMapperBase::SetConfigPath(const wxString& prefix)
310 {
311 wxCHECK_RET( !prefix.IsEmpty() && prefix[0] == wxCONFIG_PATH_SEPARATOR,
312 wxT("an absolute path should be given to wxFontMapper::SetConfigPath()") );
313
314 m_configRootPath = prefix;
315 }
316
317 // ----------------------------------------------------------------------------
318 // get config object and path for it
319 // ----------------------------------------------------------------------------
320
321 wxConfigBase *wxFontMapperBase::GetConfig()
322 {
323 if ( !m_config )
324 {
325 // try the default
326 m_config = wxConfig::Get(false /*don't create on demand*/ );
327
328 if ( !m_config )
329 {
330 // we still want to have a config object because otherwise we would
331 // keep asking the user the same questions in the interactive mode,
332 // so create a dummy config which won't write to any files/registry
333 // but will allow us to remember the results of the questions at
334 // least during this run
335 m_config = new wxMemoryConfig;
336 m_configIsDummy = true;
337 // VS: we can't call wxConfig::Set(m_config) here because that would
338 // disable automatic wxConfig instance creation if this code was
339 // called before wxApp::OnInit (this happens in wxGTK -- it sets
340 // default wxFont encoding in wxApp::Initialize())
341 }
342 }
343
344 if ( m_configIsDummy && wxConfig::Get(false) != NULL )
345 {
346 // VS: in case we created dummy m_config (see above), we want to switch back
347 // to the real one as soon as one becomes available.
348 delete m_config;
349 m_config = wxConfig::Get(false);
350 m_configIsDummy = false;
351 // FIXME: ideally, we should add keys from dummy config to the real one now,
352 // but it is a low-priority task because typical wxWin application
353 // either doesn't use wxConfig at all or creates wxConfig object in
354 // wxApp::OnInit(), before any real interaction with the user takes
355 // place...
356 }
357
358 return m_config;
359 }
360
361 const wxString& wxFontMapperBase::GetConfigPath()
362 {
363 if ( !m_configRootPath )
364 {
365 // use the default
366 m_configRootPath = GetDefaultConfigPath();
367 }
368
369 return m_configRootPath;
370 }
371
372 // ----------------------------------------------------------------------------
373 // config helpers
374 // ----------------------------------------------------------------------------
375
376 bool wxFontMapperBase::ChangePath(const wxString& pathNew, wxString *pathOld)
377 {
378 wxConfigBase *config = GetConfig();
379 if ( !config )
380 return false;
381
382 *pathOld = config->GetPath();
383
384 wxString path = GetConfigPath();
385 if ( path.IsEmpty() || path.Last() != wxCONFIG_PATH_SEPARATOR )
386 {
387 path += wxCONFIG_PATH_SEPARATOR;
388 }
389
390 wxASSERT_MSG( !pathNew || (pathNew[0] != wxCONFIG_PATH_SEPARATOR),
391 wxT("should be a relative path") );
392
393 path += pathNew;
394
395 config->SetPath(path);
396
397 return true;
398 }
399
400 void wxFontMapperBase::RestorePath(const wxString& pathOld)
401 {
402 GetConfig()->SetPath(pathOld);
403 }
404
405 #endif
406
407 // ----------------------------------------------------------------------------
408 // charset/encoding correspondence
409 // ----------------------------------------------------------------------------
410
411 wxFontEncoding
412 wxFontMapperBase::CharsetToEncoding(const wxString& charset,
413 bool WXUNUSED(interactive))
414 {
415 int enc = NonInteractiveCharsetToEncoding(charset);
416 if ( enc == wxFONTENCODING_UNKNOWN )
417 {
418 // we should return wxFONTENCODING_SYSTEM from here for unknown
419 // encodings
420 enc = wxFONTENCODING_SYSTEM;
421 }
422
423 return (wxFontEncoding)enc;
424 }
425
426 int
427 wxFontMapperBase::NonInteractiveCharsetToEncoding(const wxString& charset)
428 {
429 wxFontEncoding encoding = wxFONTENCODING_SYSTEM;
430
431 // we're going to modify it, make a copy
432 wxString cs = charset;
433
434 #if wxUSE_CONFIG && wxUSE_FILECONFIG
435 // first try the user-defined settings
436 wxFontMapperPathChanger path(this, FONTMAPPER_CHARSET_PATH);
437 if ( path.IsOk() )
438 {
439 wxConfigBase *config = GetConfig();
440
441 // do we have an encoding for this charset?
442 long value = config->Read(charset, -1l);
443 if ( value != -1 )
444 {
445 if ( value == wxFONTENCODING_UNKNOWN )
446 {
447 // don't try to find it, in particular don't ask the user
448 return value;
449 }
450
451 if ( value >= 0 && value <= wxFONTENCODING_MAX )
452 {
453 encoding = (wxFontEncoding)value;
454 }
455 else
456 {
457 wxLogDebug(wxT("corrupted config data: invalid encoding %ld for charset '%s' ignored"),
458 value, charset.c_str());
459 }
460 }
461
462 if ( encoding == wxFONTENCODING_SYSTEM )
463 {
464 // may be we have an alias?
465 config->SetPath(FONTMAPPER_CHARSET_ALIAS_PATH);
466
467 wxString alias = config->Read(charset);
468 if ( !alias.IsEmpty() )
469 {
470 // yes, we do - use it instead
471 cs = alias;
472 }
473 }
474 }
475 #endif // wxUSE_CONFIG
476
477 // if didn't find it there, try to recognize it ourselves
478 if ( encoding == wxFONTENCODING_SYSTEM )
479 {
480 // trim any spaces
481 cs.Trim(true);
482 cs.Trim(false);
483
484 // discard the optional quotes
485 if ( !cs.empty() )
486 {
487 if ( cs[0u] == _T('"') && cs.Last() == _T('"') )
488 {
489 cs = wxString(cs.c_str(), cs.length() - 1);
490 }
491 }
492
493 for ( size_t i = 0; i < WXSIZEOF(gs_encodingNames); ++i )
494 {
495 for ( const wxChar** encName = gs_encodingNames[i]; *encName; ++encName )
496 {
497 if ( cs.CmpNoCase(*encName) == 0 )
498 return gs_encodings[i];
499 }
500 }
501
502 cs.MakeUpper();
503
504 if ( cs.Left(3) == wxT("ISO") )
505 {
506 // the dash is optional (or, to be exact, it is not, but
507 // several brokenmails "forget" it)
508 const wxChar *p = cs.c_str() + 3;
509 if ( *p == wxT('-') )
510 p++;
511
512 // printf( "iso %s\n", (const char*) cs.ToAscii() );
513
514 unsigned int value;
515 if ( wxSscanf(p, wxT("8859-%u"), &value) == 1 )
516 {
517 // printf( "value %d\n", (int)value );
518
519 // make it 0 based and check that it is strictly positive in
520 // the process (no such thing as iso8859-0 encoding)
521 if ( (value-- > 0) &&
522 (value < wxFONTENCODING_ISO8859_MAX -
523 wxFONTENCODING_ISO8859_1) )
524 {
525 // it's a valid ISO8859 encoding
526 value += wxFONTENCODING_ISO8859_1;
527 encoding = (wxFontEncoding)value;
528 }
529 }
530 }
531 else if ( cs.Left(4) == wxT("8859") )
532 {
533 const wxChar *p = cs.c_str();
534
535 unsigned int value;
536 if ( wxSscanf(p, wxT("8859-%u"), &value) == 1 )
537 {
538 // printf( "value %d\n", (int)value );
539
540 // make it 0 based and check that it is strictly positive in
541 // the process (no such thing as iso8859-0 encoding)
542 if ( (value-- > 0) &&
543 (value < wxFONTENCODING_ISO8859_MAX -
544 wxFONTENCODING_ISO8859_1) )
545 {
546 // it's a valid ISO8859 encoding
547 value += wxFONTENCODING_ISO8859_1;
548 encoding = (wxFontEncoding)value;
549 }
550 }
551 }
552 else // check for Windows charsets
553 {
554 size_t len;
555 if ( cs.Left(7) == wxT("WINDOWS") )
556 {
557 len = 7;
558 }
559 else if ( cs.Left(2) == wxT("CP") )
560 {
561 len = 2;
562 }
563 else // not a Windows encoding
564 {
565 len = 0;
566 }
567
568 if ( len )
569 {
570 const wxChar *p = cs.c_str() + len;
571 if ( *p == wxT('-') )
572 p++;
573
574 int value;
575 if ( wxSscanf(p, wxT("%u"), &value) == 1 )
576 {
577 if ( value >= 1250 )
578 {
579 value -= 1250;
580 if ( value < wxFONTENCODING_CP12_MAX -
581 wxFONTENCODING_CP1250 )
582 {
583 // a valid Windows code page
584 value += wxFONTENCODING_CP1250;
585 encoding = (wxFontEncoding)value;
586 }
587 }
588
589 switch ( value )
590 {
591 case 874:
592 encoding = wxFONTENCODING_CP874;
593 break;
594
595 case 932:
596 encoding = wxFONTENCODING_CP932;
597 break;
598
599 case 936:
600 encoding = wxFONTENCODING_CP936;
601 break;
602
603 case 949:
604 encoding = wxFONTENCODING_CP949;
605 break;
606
607 case 950:
608 encoding = wxFONTENCODING_CP950;
609 break;
610 }
611 }
612 }
613 }
614 //else: unknown
615 }
616
617 return encoding;
618 }
619
620 /* static */
621 size_t wxFontMapperBase::GetSupportedEncodingsCount()
622 {
623 return WXSIZEOF(gs_encodings);
624 }
625
626 /* static */
627 wxFontEncoding wxFontMapperBase::GetEncoding(size_t n)
628 {
629 wxCHECK_MSG( n < WXSIZEOF(gs_encodings), wxFONTENCODING_SYSTEM,
630 _T("wxFontMapper::GetEncoding(): invalid index") );
631
632 return gs_encodings[n];
633 }
634
635 /* static */
636 wxString wxFontMapperBase::GetEncodingDescription(wxFontEncoding encoding)
637 {
638 if ( encoding == wxFONTENCODING_DEFAULT )
639 {
640 return _("Default encoding");
641 }
642
643 const size_t count = WXSIZEOF(gs_encodingDescs);
644
645 for ( size_t i = 0; i < count; i++ )
646 {
647 if ( gs_encodings[i] == encoding )
648 {
649 return wxGetTranslation(gs_encodingDescs[i]);
650 }
651 }
652
653 wxString str;
654 str.Printf(_("Unknown encoding (%d)"), encoding);
655
656 return str;
657 }
658
659 /* static */
660 wxString wxFontMapperBase::GetEncodingName(wxFontEncoding encoding)
661 {
662 if ( encoding == wxFONTENCODING_DEFAULT )
663 {
664 return _("default");
665 }
666
667 const size_t count = WXSIZEOF(gs_encodingNames);
668
669 for ( size_t i = 0; i < count; i++ )
670 {
671 if ( gs_encodings[i] == encoding )
672 {
673 return gs_encodingNames[i][0];
674 }
675 }
676
677 wxString str;
678 str.Printf(_("unknown-%d"), encoding);
679
680 return str;
681 }
682
683 /* static */
684 const wxChar** wxFontMapperBase::GetAllEncodingNames(wxFontEncoding encoding)
685 {
686 static const wxChar* dummy[] = { NULL };
687
688 for ( size_t i = 0; i < WXSIZEOF(gs_encodingNames); i++ )
689 {
690 if ( gs_encodings[i] == encoding )
691 {
692 return gs_encodingNames[i];
693 }
694 }
695
696 return dummy;
697 }
698
699 /* static */
700 wxFontEncoding wxFontMapperBase::GetEncodingFromName(const wxString& name)
701 {
702 const size_t count = WXSIZEOF(gs_encodingNames);
703
704 for ( size_t i = 0; i < count; i++ )
705 {
706 for ( const wxChar** encName = gs_encodingNames[i]; *encName; ++encName )
707 {
708 if ( name.CmpNoCase(*encName) == 0 )
709 return gs_encodings[i];
710 }
711 }
712
713 if ( name == _("default") )
714 {
715 return wxFONTENCODING_DEFAULT;
716 }
717
718 return wxFONTENCODING_MAX;
719 }
720
721 #endif // wxUSE_FONTMAP
722