Add one more encoding name for EUC-JP for Solaris 8.
[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 };
100
101 // the descriptions for them
102 static const wxChar* gs_encodingDescs[] =
103 {
104 wxTRANSLATE( "Western European (ISO-8859-1)" ),
105 wxTRANSLATE( "Central European (ISO-8859-2)" ),
106 wxTRANSLATE( "Esperanto (ISO-8859-3)" ),
107 wxTRANSLATE( "Baltic (old) (ISO-8859-4)" ),
108 wxTRANSLATE( "Cyrillic (ISO-8859-5)" ),
109 wxTRANSLATE( "Arabic (ISO-8859-6)" ),
110 wxTRANSLATE( "Greek (ISO-8859-7)" ),
111 wxTRANSLATE( "Hebrew (ISO-8859-8)" ),
112 wxTRANSLATE( "Turkish (ISO-8859-9)" ),
113 wxTRANSLATE( "Nordic (ISO-8859-10)" ),
114 wxTRANSLATE( "Thai (ISO-8859-11)" ),
115 wxTRANSLATE( "Indian (ISO-8859-12)" ),
116 wxTRANSLATE( "Baltic (ISO-8859-13)" ),
117 wxTRANSLATE( "Celtic (ISO-8859-14)" ),
118 wxTRANSLATE( "Western European with Euro (ISO-8859-15)" ),
119 wxTRANSLATE( "KOI8-R" ),
120 wxTRANSLATE( "KOI8-U" ),
121 wxTRANSLATE( "Windows Thai (CP 874)" ),
122 wxTRANSLATE( "Windows Japanese (CP 932)" ),
123 wxTRANSLATE( "Windows Chinese Simplified (CP 936)" ),
124 wxTRANSLATE( "Windows Korean (CP 949)" ),
125 wxTRANSLATE( "Windows Chinese Traditional (CP 950)" ),
126 wxTRANSLATE( "Windows Central European (CP 1250)" ),
127 wxTRANSLATE( "Windows Cyrillic (CP 1251)" ),
128 wxTRANSLATE( "Windows Western European (CP 1252)" ),
129 wxTRANSLATE( "Windows Greek (CP 1253)" ),
130 wxTRANSLATE( "Windows Turkish (CP 1254)" ),
131 wxTRANSLATE( "Windows Hebrew (CP 1255)" ),
132 wxTRANSLATE( "Windows Arabic (CP 1256)" ),
133 wxTRANSLATE( "Windows Baltic (CP 1257)" ),
134 wxTRANSLATE( "Windows/DOS OEM (CP 437)" ),
135 wxTRANSLATE( "Unicode 7 bit (UTF-7)" ),
136 wxTRANSLATE( "Unicode 8 bit (UTF-8)" ),
137 wxTRANSLATE( "Unicode 16 bit (UTF-16)" ),
138 wxTRANSLATE( "Unicode 16 bit Big Endian (UTF-16BE)" ),
139 wxTRANSLATE( "Unicode 16 bit Little Endian (UTF-16LE)" ),
140 wxTRANSLATE( "Unicode 32 bit (UTF-32)" ),
141 wxTRANSLATE( "Unicode 32 bit Big Endian (UTF-32BE)" ),
142 wxTRANSLATE( "Unicode 32 bit Little Endian (UTF-32LE)" ),
143 wxTRANSLATE( "Extended Unix Codepage for Japanese (EUC-JP)" ),
144 };
145
146 // and the internal names (these are not translated on purpose!)
147 static const wxChar* gs_encodingNames[] =
148 {
149 wxT( "iso-8859-1" ),
150 wxT( "iso-8859-2" ),
151 wxT( "iso-8859-3" ),
152 wxT( "iso-8859-4" ),
153 wxT( "iso-8859-5" ),
154 wxT( "iso-8859-6" ),
155 wxT( "iso-8859-7" ),
156 wxT( "iso-8859-8" ),
157 wxT( "iso-8859-9" ),
158 wxT( "iso-8859-10" ),
159 wxT( "iso-8859-11" ),
160 wxT( "iso-8859-12" ),
161 wxT( "iso-8859-13" ),
162 wxT( "iso-8859-14" ),
163 wxT( "iso-8859-15" ),
164 wxT( "koi8-r" ),
165 wxT( "koi8-u" ),
166 wxT( "windows-874" ),
167 wxT( "windows-932" ),
168 wxT( "windows-936" ),
169 wxT( "windows-949" ),
170 wxT( "windows-950" ),
171 wxT( "windows-1250" ),
172 wxT( "windows-1251" ),
173 wxT( "windows-1252" ),
174 wxT( "windows-1253" ),
175 wxT( "windows-1254" ),
176 wxT( "windows-1255" ),
177 wxT( "windows-1256" ),
178 wxT( "windows-1257" ),
179 wxT( "windows-437" ),
180 wxT( "utf-7" ),
181 wxT( "utf-8" ),
182 wxT( "utf-16" ),
183 wxT( "utf-16be" ),
184 wxT( "utf-16le" ),
185 wxT( "utf-32" ),
186 wxT( "utf-32be" ),
187 wxT( "utf-32le" ),
188 wxT( "euc-jp" ),
189 };
190
191 wxCOMPILE_TIME_ASSERT( WXSIZEOF(gs_encodingDescs) == WXSIZEOF(gs_encodings) &&
192 WXSIZEOF(gs_encodingNames) == WXSIZEOF(gs_encodings),
193 EncodingsArraysNotInSync );
194
195 // ----------------------------------------------------------------------------
196 // private classes
197 // ----------------------------------------------------------------------------
198
199 // clean up the font mapper object
200 class wxFontMapperModule : public wxModule
201 {
202 public:
203 wxFontMapperModule() : wxModule() { }
204 virtual bool OnInit() { return true; }
205 virtual void OnExit() { delete (wxFontMapperBase*)wxFontMapperBase::Set(NULL); }
206
207 DECLARE_DYNAMIC_CLASS(wxFontMapperModule)
208 };
209
210 IMPLEMENT_DYNAMIC_CLASS(wxFontMapperModule, wxModule)
211
212
213 // ============================================================================
214 // wxFontMapperBase implementation
215 // ============================================================================
216
217 wxFontMapper *wxFontMapperBase::sm_instance = NULL;
218
219 // ----------------------------------------------------------------------------
220 // ctor and dtor
221 // ----------------------------------------------------------------------------
222
223 wxFontMapperBase::wxFontMapperBase()
224 {
225 #if wxUSE_CONFIG && wxUSE_FILECONFIG
226 m_config = NULL;
227 m_configIsDummy = false;
228 #endif // wxUSE_CONFIG
229 }
230
231 wxFontMapperBase::~wxFontMapperBase()
232 {
233 #if wxUSE_CONFIG && wxUSE_FILECONFIG
234 if ( m_configIsDummy )
235 delete m_config;
236 #endif // wxUSE_CONFIG
237 }
238
239 bool wxFontMapperBase::IsWxFontMapper()
240 { return false; }
241
242 /* static */
243 wxFontMapperBase *wxFontMapperBase::Get()
244 {
245 if ( !sm_instance )
246 {
247 wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
248 if ( traits )
249 {
250 sm_instance = traits->CreateFontMapper();
251
252 wxASSERT_MSG( sm_instance,
253 _T("wxAppTraits::CreateFontMapper() failed") );
254 }
255
256 if ( !sm_instance )
257 {
258 // last resort: we must create something because the existing code
259 // relies on always having a valid font mapper object
260 sm_instance = (wxFontMapper *)new wxFontMapperBase;
261 }
262 }
263
264 return (wxFontMapperBase*)sm_instance;
265 }
266
267 /* static */
268 wxFontMapper *wxFontMapperBase::Set(wxFontMapper *mapper)
269 {
270 wxFontMapper *old = sm_instance;
271 sm_instance = mapper;
272 return old;
273 }
274
275 #if wxUSE_CONFIG && wxUSE_FILECONFIG
276
277 // ----------------------------------------------------------------------------
278 // config usage customisation
279 // ----------------------------------------------------------------------------
280
281 /* static */
282 const wxChar *wxFontMapperBase::GetDefaultConfigPath()
283 {
284 return FONTMAPPER_ROOT_PATH;
285 }
286
287 void wxFontMapperBase::SetConfigPath(const wxString& prefix)
288 {
289 wxCHECK_RET( !prefix.IsEmpty() && prefix[0] == wxCONFIG_PATH_SEPARATOR,
290 wxT("an absolute path should be given to wxFontMapper::SetConfigPath()") );
291
292 m_configRootPath = prefix;
293 }
294
295 // ----------------------------------------------------------------------------
296 // get config object and path for it
297 // ----------------------------------------------------------------------------
298
299 wxConfigBase *wxFontMapperBase::GetConfig()
300 {
301 if ( !m_config )
302 {
303 // try the default
304 m_config = wxConfig::Get(false /*don't create on demand*/ );
305
306 if ( !m_config )
307 {
308 // we still want to have a config object because otherwise we would
309 // keep asking the user the same questions in the interactive mode,
310 // so create a dummy config which won't write to any files/registry
311 // but will allow us to remember the results of the questions at
312 // least during this run
313 m_config = new wxMemoryConfig;
314 m_configIsDummy = true;
315 // VS: we can't call wxConfig::Set(m_config) here because that would
316 // disable automatic wxConfig instance creation if this code was
317 // called before wxApp::OnInit (this happens in wxGTK -- it sets
318 // default wxFont encoding in wxApp::Initialize())
319 }
320 }
321
322 if ( m_configIsDummy && wxConfig::Get(false) != NULL )
323 {
324 // VS: in case we created dummy m_config (see above), we want to switch back
325 // to the real one as soon as one becomes available.
326 delete m_config;
327 m_config = wxConfig::Get(false);
328 m_configIsDummy = false;
329 // FIXME: ideally, we should add keys from dummy config to the real one now,
330 // but it is a low-priority task because typical wxWin application
331 // either doesn't use wxConfig at all or creates wxConfig object in
332 // wxApp::OnInit(), before any real interaction with the user takes
333 // place...
334 }
335
336 return m_config;
337 }
338
339 const wxString& wxFontMapperBase::GetConfigPath()
340 {
341 if ( !m_configRootPath )
342 {
343 // use the default
344 m_configRootPath = GetDefaultConfigPath();
345 }
346
347 return m_configRootPath;
348 }
349
350 // ----------------------------------------------------------------------------
351 // config helpers
352 // ----------------------------------------------------------------------------
353
354 bool wxFontMapperBase::ChangePath(const wxString& pathNew, wxString *pathOld)
355 {
356 wxConfigBase *config = GetConfig();
357 if ( !config )
358 return false;
359
360 *pathOld = config->GetPath();
361
362 wxString path = GetConfigPath();
363 if ( path.IsEmpty() || path.Last() != wxCONFIG_PATH_SEPARATOR )
364 {
365 path += wxCONFIG_PATH_SEPARATOR;
366 }
367
368 wxASSERT_MSG( !pathNew || (pathNew[0] != wxCONFIG_PATH_SEPARATOR),
369 wxT("should be a relative path") );
370
371 path += pathNew;
372
373 config->SetPath(path);
374
375 return true;
376 }
377
378 void wxFontMapperBase::RestorePath(const wxString& pathOld)
379 {
380 GetConfig()->SetPath(pathOld);
381 }
382
383 #endif
384
385 // ----------------------------------------------------------------------------
386 // charset/encoding correspondence
387 // ----------------------------------------------------------------------------
388
389 wxFontEncoding
390 wxFontMapperBase::CharsetToEncoding(const wxString& charset,
391 bool WXUNUSED(interactive))
392 {
393 int enc = NonInteractiveCharsetToEncoding(charset);
394 if ( enc == wxFONTENCODING_UNKNOWN )
395 {
396 // we should return wxFONTENCODING_SYSTEM from here for unknown
397 // encodings
398 enc = wxFONTENCODING_SYSTEM;
399 }
400
401 return (wxFontEncoding)enc;
402 }
403
404 int
405 wxFontMapperBase::NonInteractiveCharsetToEncoding(const wxString& charset)
406 {
407 wxFontEncoding encoding = wxFONTENCODING_SYSTEM;
408
409 // we're going to modify it, make a copy
410 wxString cs = charset;
411
412 #if wxUSE_CONFIG && wxUSE_FILECONFIG
413 // first try the user-defined settings
414 wxFontMapperPathChanger path(this, FONTMAPPER_CHARSET_PATH);
415 if ( path.IsOk() )
416 {
417 wxConfigBase *config = GetConfig();
418
419 // do we have an encoding for this charset?
420 long value = config->Read(charset, -1l);
421 if ( value != -1 )
422 {
423 if ( value == wxFONTENCODING_UNKNOWN )
424 {
425 // don't try to find it, in particular don't ask the user
426 return value;
427 }
428
429 if ( value >= 0 && value <= wxFONTENCODING_MAX )
430 {
431 encoding = (wxFontEncoding)value;
432 }
433 else
434 {
435 wxLogDebug(wxT("corrupted config data: invalid encoding %ld for charset '%s' ignored"),
436 value, charset.c_str());
437 }
438 }
439
440 if ( encoding == wxFONTENCODING_SYSTEM )
441 {
442 // may be we have an alias?
443 config->SetPath(FONTMAPPER_CHARSET_ALIAS_PATH);
444
445 wxString alias = config->Read(charset);
446 if ( !alias.IsEmpty() )
447 {
448 // yes, we do - use it instead
449 cs = alias;
450 }
451 }
452 }
453 #endif // wxUSE_CONFIG
454
455 // if didn't find it there, try to recognize it ourselves
456 if ( encoding == wxFONTENCODING_SYSTEM )
457 {
458 // trim any spaces
459 cs.Trim(true);
460 cs.Trim(false);
461
462 // discard the optional quotes
463 if ( !cs.empty() )
464 {
465 if ( cs[0u] == _T('"') && cs.Last() == _T('"') )
466 {
467 cs = wxString(cs.c_str(), cs.length() - 1);
468 }
469 }
470
471 cs.MakeUpper();
472
473 if ( cs.empty() || cs == _T("US-ASCII") )
474 {
475 encoding = wxFONTENCODING_DEFAULT;
476 }
477 else if ( cs == wxT("UTF-7") )
478 {
479 encoding = wxFONTENCODING_UTF7;
480 }
481 else if ( cs == wxT("UTF-8") )
482 {
483 encoding = wxFONTENCODING_UTF8;
484 }
485 else if ( cs == wxT("UTF-16") )
486 {
487 encoding = wxFONTENCODING_UTF16;
488 }
489 else if ( cs == wxT("UTF-16BE") )
490 {
491 encoding = wxFONTENCODING_UTF16BE;
492 }
493 else if ( cs == wxT("UTF-16LE") )
494 {
495 encoding = wxFONTENCODING_UTF16LE;
496 }
497 else if ( cs == wxT("UTF-32") || cs == wxT("UCS-4") )
498 {
499 encoding = wxFONTENCODING_UTF32;
500 }
501 else if ( cs == wxT("UTF-32BE") || cs == wxT("UCS-4BE") )
502 {
503 encoding = wxFONTENCODING_UTF32BE;
504 }
505 else if ( cs == wxT("UTF-32LE") || cs == wxT("UCS-4LE") )
506 {
507 encoding = wxFONTENCODING_UTF32LE;
508 }
509 else if ( cs == wxT("GB2312") )
510 {
511 encoding = wxFONTENCODING_GB2312;
512 }
513 else if ( cs == wxT("BIG5") )
514 {
515 encoding = wxFONTENCODING_BIG5;
516 }
517 else if ( cs == wxT("SJIS") ||
518 cs == wxT("SHIFT_JIS") ||
519 cs == wxT("SHIFT-JIS") )
520 {
521 encoding = wxFONTENCODING_SHIFT_JIS;
522 }
523 else if ( cs == wxT("EUC-JP") ||
524 cs == wxT("EUC_JP") ||
525 cs == wxT("EUCJP") )
526 {
527 encoding = wxFONTENCODING_EUC_JP;
528 }
529 else if ( cs == wxT("EUC-KR") ||
530 cs == wxT("EUC_KR") )
531 {
532 encoding = wxFONTENCODING_CP949;
533 }
534 else if ( cs == wxT("KOI8-R") ||
535 cs == wxT("KOI8-RU") )
536 {
537 // although koi8-ru is not strictly speaking the same as koi8-r,
538 // they are similar enough to make mapping it to koi8 better than
539 // not recognizing it at all
540 encoding = wxFONTENCODING_KOI8;
541 }
542 else if ( cs == wxT("KOI8-U") )
543 {
544 encoding = wxFONTENCODING_KOI8_U;
545 }
546 else if ( cs.Left(3) == wxT("ISO") )
547 {
548 // the dash is optional (or, to be exact, it is not, but
549 // several brokenmails "forget" it)
550 const wxChar *p = cs.c_str() + 3;
551 if ( *p == wxT('-') )
552 p++;
553
554 // printf( "iso %s\n", (const char*) cs.ToAscii() );
555
556 unsigned int value;
557 if ( wxSscanf(p, wxT("8859-%u"), &value) == 1 )
558 {
559 // printf( "value %d\n", (int)value );
560
561 // make it 0 based and check that it is strictly positive in
562 // the process (no such thing as iso8859-0 encoding)
563 if ( (value-- > 0) &&
564 (value < wxFONTENCODING_ISO8859_MAX -
565 wxFONTENCODING_ISO8859_1) )
566 {
567 // it's a valid ISO8859 encoding
568 value += wxFONTENCODING_ISO8859_1;
569 encoding = (wxFontEncoding)value;
570 }
571 }
572 }
573 else if ( cs.Left(4) == wxT("8859") )
574 {
575 const wxChar *p = cs.c_str();
576
577 unsigned int value;
578 if ( wxSscanf(p, wxT("8859-%u"), &value) == 1 )
579 {
580 // printf( "value %d\n", (int)value );
581
582 // make it 0 based and check that it is strictly positive in
583 // the process (no such thing as iso8859-0 encoding)
584 if ( (value-- > 0) &&
585 (value < wxFONTENCODING_ISO8859_MAX -
586 wxFONTENCODING_ISO8859_1) )
587 {
588 // it's a valid ISO8859 encoding
589 value += wxFONTENCODING_ISO8859_1;
590 encoding = (wxFontEncoding)value;
591 }
592 }
593 }
594 else // check for Windows charsets
595 {
596 size_t len;
597 if ( cs.Left(7) == wxT("WINDOWS") )
598 {
599 len = 7;
600 }
601 else if ( cs.Left(2) == wxT("CP") )
602 {
603 len = 2;
604 }
605 else // not a Windows encoding
606 {
607 len = 0;
608 }
609
610 if ( len )
611 {
612 const wxChar *p = cs.c_str() + len;
613 if ( *p == wxT('-') )
614 p++;
615
616 int value;
617 if ( wxSscanf(p, wxT("%u"), &value) == 1 )
618 {
619 if ( value >= 1250 )
620 {
621 value -= 1250;
622 if ( value < wxFONTENCODING_CP12_MAX -
623 wxFONTENCODING_CP1250 )
624 {
625 // a valid Windows code page
626 value += wxFONTENCODING_CP1250;
627 encoding = (wxFontEncoding)value;
628 }
629 }
630
631 switch ( value )
632 {
633 case 874:
634 encoding = wxFONTENCODING_CP874;
635 break;
636
637 case 932:
638 encoding = wxFONTENCODING_CP932;
639 break;
640
641 case 936:
642 encoding = wxFONTENCODING_CP936;
643 break;
644
645 case 949:
646 encoding = wxFONTENCODING_CP949;
647 break;
648
649 case 950:
650 encoding = wxFONTENCODING_CP950;
651 break;
652 }
653 }
654 }
655 }
656 //else: unknown
657 }
658
659 return encoding;
660 }
661
662 /* static */
663 size_t wxFontMapperBase::GetSupportedEncodingsCount()
664 {
665 return WXSIZEOF(gs_encodings);
666 }
667
668 /* static */
669 wxFontEncoding wxFontMapperBase::GetEncoding(size_t n)
670 {
671 wxCHECK_MSG( n < WXSIZEOF(gs_encodings), wxFONTENCODING_SYSTEM,
672 _T("wxFontMapper::GetEncoding(): invalid index") );
673
674 return gs_encodings[n];
675 }
676
677 /* static */
678 wxString wxFontMapperBase::GetEncodingDescription(wxFontEncoding encoding)
679 {
680 if ( encoding == wxFONTENCODING_DEFAULT )
681 {
682 return _("Default encoding");
683 }
684
685 const size_t count = WXSIZEOF(gs_encodingDescs);
686
687 for ( size_t i = 0; i < count; i++ )
688 {
689 if ( gs_encodings[i] == encoding )
690 {
691 return wxGetTranslation(gs_encodingDescs[i]);
692 }
693 }
694
695 wxString str;
696 str.Printf(_("Unknown encoding (%d)"), encoding);
697
698 return str;
699 }
700
701 /* static */
702 wxString wxFontMapperBase::GetEncodingName(wxFontEncoding encoding)
703 {
704 if ( encoding == wxFONTENCODING_DEFAULT )
705 {
706 return _("default");
707 }
708
709 const size_t count = WXSIZEOF(gs_encodingNames);
710
711 for ( size_t i = 0; i < count; i++ )
712 {
713 if ( gs_encodings[i] == encoding )
714 {
715 return gs_encodingNames[i];
716 }
717 }
718
719 wxString str;
720 str.Printf(_("unknown-%d"), encoding);
721
722 return str;
723 }
724
725 /* static */
726 wxFontEncoding wxFontMapperBase::GetEncodingFromName(const wxString& name)
727 {
728 const size_t count = WXSIZEOF(gs_encodingNames);
729
730 for ( size_t i = 0; i < count; i++ )
731 {
732 if ( gs_encodingNames[i] == name )
733 {
734 return gs_encodings[i];
735 }
736 }
737
738 if ( name == _("default") )
739 {
740 return wxFONTENCODING_DEFAULT;
741 }
742
743 return wxFONTENCODING_MAX;
744 }
745
746 #endif // wxUSE_FONTMAP
747