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