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