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
,
104 // the descriptions for them
105 static const wxChar
* gs_encodingDescs
[] =
107 wxTRANSLATE( "Western European (ISO-8859-1)" ),
108 wxTRANSLATE( "Central European (ISO-8859-2)" ),
109 wxTRANSLATE( "Esperanto (ISO-8859-3)" ),
110 wxTRANSLATE( "Baltic (old) (ISO-8859-4)" ),
111 wxTRANSLATE( "Cyrillic (ISO-8859-5)" ),
112 wxTRANSLATE( "Arabic (ISO-8859-6)" ),
113 wxTRANSLATE( "Greek (ISO-8859-7)" ),
114 wxTRANSLATE( "Hebrew (ISO-8859-8)" ),
115 wxTRANSLATE( "Turkish (ISO-8859-9)" ),
116 wxTRANSLATE( "Nordic (ISO-8859-10)" ),
117 wxTRANSLATE( "Thai (ISO-8859-11)" ),
118 wxTRANSLATE( "Indian (ISO-8859-12)" ),
119 wxTRANSLATE( "Baltic (ISO-8859-13)" ),
120 wxTRANSLATE( "Celtic (ISO-8859-14)" ),
121 wxTRANSLATE( "Western European with Euro (ISO-8859-15)" ),
122 wxTRANSLATE( "KOI8-R" ),
123 wxTRANSLATE( "KOI8-U" ),
124 wxTRANSLATE( "Windows Thai (CP 874)" ),
125 wxTRANSLATE( "Windows Japanese (CP 932)" ),
126 wxTRANSLATE( "Windows Chinese Simplified (CP 936)" ),
127 wxTRANSLATE( "Windows Korean (CP 949)" ),
128 wxTRANSLATE( "Windows Chinese Traditional (CP 950)" ),
129 wxTRANSLATE( "Windows Central European (CP 1250)" ),
130 wxTRANSLATE( "Windows Cyrillic (CP 1251)" ),
131 wxTRANSLATE( "Windows Western European (CP 1252)" ),
132 wxTRANSLATE( "Windows Greek (CP 1253)" ),
133 wxTRANSLATE( "Windows Turkish (CP 1254)" ),
134 wxTRANSLATE( "Windows Hebrew (CP 1255)" ),
135 wxTRANSLATE( "Windows Arabic (CP 1256)" ),
136 wxTRANSLATE( "Windows Baltic (CP 1257)" ),
137 wxTRANSLATE( "Windows/DOS OEM (CP 437)" ),
138 wxTRANSLATE( "Unicode 7 bit (UTF-7)" ),
139 wxTRANSLATE( "Unicode 8 bit (UTF-8)" ),
140 #ifdef WORDS_BIGENDIAN
141 wxTRANSLATE( "Unicode 16 bit (UTF-16)" ),
142 wxTRANSLATE( "Unicode 16 bit Little Endian (UTF-16LE)" ),
143 wxTRANSLATE( "Unicode 32 bit (UTF-32)" ),
144 wxTRANSLATE( "Unicode 32 bit Little Endian (UTF-32LE)" ),
145 #else // WORDS_BIGENDIAN
146 wxTRANSLATE( "Unicode 16 bit Big Endian (UTF-16BE)" ),
147 wxTRANSLATE( "Unicode 16 bit (UTF-16)" ),
148 wxTRANSLATE( "Unicode 32 bit Big Endian (UTF-32BE)" ),
149 wxTRANSLATE( "Unicode 32 bit (UTF-32)" ),
150 #endif // WORDS_BIGENDIAN
151 wxTRANSLATE( "Extended Unix Codepage for Japanese (EUC-JP)" ),
152 wxTRANSLATE( "US-ASCII" ),
153 wxTRANSLATE( "BIG5" ),
154 wxTRANSLATE( "SHIFT-JIS" ),
155 wxTRANSLATE( "GB-2312" ),
158 // and the internal names (these are not translated on purpose!)
159 static const wxChar
* gs_encodingNames
[WXSIZEOF(gs_encodingDescs
)][9] =
161 // names from the columns correspond to these OS:
162 // Linux Solaris and IRIX HP-UX AIX
163 { _T("ISO-8859-1"), _T("ISO8859-1"), _T("iso88591"), _T("8859-1"), wxT("iso_8859_1"), NULL
},
164 { _T("ISO-8859-2"), _T("ISO8859-2"), _T("iso88592"), _T("8859-2"), NULL
},
165 { _T("ISO-8859-3"), _T("ISO8859-3"), _T("iso88593"), _T("8859-3"), NULL
},
166 { _T("ISO-8859-4"), _T("ISO8859-4"), _T("iso88594"), _T("8859-4"), NULL
},
167 { _T("ISO-8859-5"), _T("ISO8859-5"), _T("iso88595"), _T("8859-5"), NULL
},
168 { _T("ISO-8859-6"), _T("ISO8859-6"), _T("iso88596"), _T("8859-6"), NULL
},
169 { _T("ISO-8859-7"), _T("ISO8859-7"), _T("iso88597"), _T("8859-7"), NULL
},
170 { _T("ISO-8859-8"), _T("ISO8859-8"), _T("iso88598"), _T("8859-8"), NULL
},
171 { _T("ISO-8859-9"), _T("ISO8859-9"), _T("iso88599"), _T("8859-9"), NULL
},
172 { _T("ISO-8859-10"), _T("ISO8859-10"), _T("iso885910"), _T("8859-10"), NULL
},
173 { _T("ISO-8859-11"), _T("ISO8859-11"), _T("iso885911"), _T("8859-11"), NULL
},
174 { _T("ISO-8859-12"), _T("ISO8859-12"), _T("iso885912"), _T("8859-12"), NULL
},
175 { _T("ISO-8859-13"), _T("ISO8859-13"), _T("iso885913"), _T("8859-13"), NULL
},
176 { _T("ISO-8859-14"), _T("ISO8859-14"), _T("iso885914"), _T("8859-14"), NULL
},
177 { _T("ISO-8859-15"), _T("ISO8859-15"), _T("iso885915"), _T("8859-15"), NULL
},
179 // although koi8-ru is not strictly speaking the same as koi8-r,
180 // they are similar enough to make mapping it to koi8 better than
181 // not recognizing it at all
182 { wxT( "KOI8-R" ), wxT( "KOI8-RU" ), NULL
},
183 { wxT( "KOI8-U" ), NULL
},
185 { wxT( "WINDOWS-874" ), wxT( "CP-874" ), wxT( "MS-874" ), wxT( "IBM-874" ), NULL
},
186 { wxT( "WINDOWS-932" ), wxT( "CP-932" ), wxT( "MS-932" ), wxT( "IBM-932" ), NULL
},
187 { wxT( "WINDOWS-936" ), wxT( "CP-936" ), wxT( "MS-936" ), wxT( "IBM-936" ), NULL
},
188 { wxT( "WINDOWS-949" ), wxT( "CP-949" ), wxT( "MS-949" ), wxT( "IBM-949" ), wxT( "EUC-KR" ), wxT( "eucKR" ), wxT( "euc_kr" ), NULL
},
189 { wxT( "WINDOWS-950" ), wxT( "CP-950" ), wxT( "MS-950" ), wxT( "IBM-950" ), NULL
},
190 { wxT( "WINDOWS-1250" ),wxT( "CP-1250" ),wxT( "MS-1250" ),wxT( "IBM-1250" ),NULL
},
191 { wxT( "WINDOWS-1251" ),wxT( "CP-1251" ),wxT( "MS-1251" ),wxT( "IBM-1251" ),NULL
},
192 { wxT( "WINDOWS-1252" ),wxT( "CP-1252" ),wxT( "MS-1252" ),wxT( "IBM-1252" ),NULL
},
193 { wxT( "WINDOWS-1253" ),wxT( "CP-1253" ),wxT( "MS-1253" ),wxT( "IBM-1253" ),NULL
},
194 { wxT( "WINDOWS-1254" ),wxT( "CP-1254" ),wxT( "MS-1254" ),wxT( "IBM-1254" ),NULL
},
195 { wxT( "WINDOWS-1255" ),wxT( "CP-1255" ),wxT( "MS-1255" ),wxT( "IBM-1255" ),NULL
},
196 { wxT( "WINDOWS-1256" ),wxT( "CP-1256" ),wxT( "MS-1256" ),wxT( "IBM-1256" ),NULL
},
197 { wxT( "WINDOWS-1257" ),wxT( "CP-1257" ),wxT( "MS-1257" ),wxT( "IBM-1257" ),NULL
},
198 { wxT( "WINDOWS-437" ), wxT( "CP-437" ), wxT( "MS-437" ), wxT( "IBM-437" ), NULL
},
200 { wxT( "UTF-7" ), NULL
},
201 { wxT( "UTF-8" ), NULL
},
202 #ifdef WORDS_BIGENDIAN
203 { wxT( "UTF-16BE" ), wxT("UCS-2BE"), wxT( "UTF-16" ), wxT("UCS-2"), NULL
},
204 { wxT( "UTF-16LE" ), wxT("UCS-2LE"), NULL
},
205 { wxT( "UTF-32BE" ), wxT( "UCS-4BE" ), wxT( "UTF-32" ), wxT( "UCS-4" ), NULL
},
206 { wxT( "UTF-32LE" ), wxT( "UCS-4LE" ), NULL
},
207 #else // WORDS_BIGENDIAN
208 { wxT( "UTF-16BE" ), wxT("UCS-2BE"), NULL
},
209 { wxT( "UTF-16LE" ), wxT("UCS-2LE"), wxT( "UTF-16" ), wxT("UCS-2"), NULL
},
210 { wxT( "UTF-32BE" ), wxT( "UCS-4BE" ), NULL
},
211 { wxT( "UTF-32LE" ), wxT( "UCS-4LE" ), wxT( "UTF-32" ), wxT( "UCS-4" ), NULL
},
212 #endif // WORDS_BIGENDIAN
214 { wxT( "EUC-JP" ), wxT( "eucJP" ), wxT( "euc_jp" ), wxT( "IBM-eucJP" ), NULL
},
216 // 646 is for Solaris, roman8 -- for HP-UX
217 { wxT( "US-ASCII" ), wxT( "ASCII" ), wxT("C"), wxT("POSIX"), wxT("ANSI_X3.4-1968"),
218 wxT("646"), wxT("roman8"), wxT( "" ), NULL
},
220 { wxT( "BIG5" ), wxT("big5"), NULL
},
221 { wxT( "SJIS" ), wxT( "SHIFT-JIS" ), wxT( "SHIFT_JIS" ), NULL
},
222 { wxT( "GB2312" ), NULL
},
225 wxCOMPILE_TIME_ASSERT( WXSIZEOF(gs_encodingDescs
) == WXSIZEOF(gs_encodings
), EncodingsArraysNotInSync
);
226 wxCOMPILE_TIME_ASSERT( WXSIZEOF(gs_encodingNames
) == WXSIZEOF(gs_encodings
), EncodingsArraysNotInSync
);
228 // ----------------------------------------------------------------------------
230 // ----------------------------------------------------------------------------
232 // clean up the font mapper object
233 class wxFontMapperModule
: public wxModule
236 wxFontMapperModule() : wxModule() { }
238 virtual bool OnInit()
240 // a dummy wxFontMapperBase object could have been created during the
241 // program startup before wxApp was created, we have to delete it to
242 // allow creating the real font mapper next time it is needed now that
243 // we can create it (when the modules are initialized, wxApp object
245 wxFontMapperBase
*fm
= wxFontMapperBase::Get();
246 if ( fm
&& fm
->IsDummy() )
247 wxFontMapperBase::Reset();
252 virtual void OnExit()
254 wxFontMapperBase::Reset();
257 DECLARE_DYNAMIC_CLASS(wxFontMapperModule
)
260 IMPLEMENT_DYNAMIC_CLASS(wxFontMapperModule
, wxModule
)
263 // ============================================================================
264 // wxFontMapperBase implementation
265 // ============================================================================
267 wxFontMapper
*wxFontMapperBase::sm_instance
= NULL
;
269 // ----------------------------------------------------------------------------
271 // ----------------------------------------------------------------------------
273 wxFontMapperBase::wxFontMapperBase()
275 #if wxUSE_CONFIG && wxUSE_FILECONFIG
276 m_configDummy
= NULL
;
277 #endif // wxUSE_CONFIG
280 wxFontMapperBase::~wxFontMapperBase()
282 #if wxUSE_CONFIG && wxUSE_FILECONFIG
284 delete m_configDummy
;
285 #endif // wxUSE_CONFIG
289 wxFontMapperBase
*wxFontMapperBase::Get()
293 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
296 sm_instance
= traits
->CreateFontMapper();
298 wxASSERT_MSG( sm_instance
,
299 _T("wxAppTraits::CreateFontMapper() failed") );
304 // last resort: we must create something because the existing code
305 // relies on always having a valid font mapper object
306 sm_instance
= (wxFontMapper
*)new wxFontMapperBase
;
310 return (wxFontMapperBase
*)sm_instance
;
314 wxFontMapper
*wxFontMapperBase::Set(wxFontMapper
*mapper
)
316 wxFontMapper
*old
= sm_instance
;
317 sm_instance
= mapper
;
322 void wxFontMapperBase::Reset()
326 // we need a cast as wxFontMapper is not fully declared here and so the
327 // compiler can't know that it derives from wxFontMapperBase (but
328 // run-time behaviour will be correct because the dtor is virtual)
329 delete (wxFontMapperBase
*)sm_instance
;
334 #if wxUSE_CONFIG && wxUSE_FILECONFIG
336 // ----------------------------------------------------------------------------
337 // config usage customisation
338 // ----------------------------------------------------------------------------
341 const wxChar
*wxFontMapperBase::GetDefaultConfigPath()
343 return FONTMAPPER_ROOT_PATH
;
346 void wxFontMapperBase::SetConfigPath(const wxString
& prefix
)
348 wxCHECK_RET( !prefix
.empty() && prefix
[0] == wxCONFIG_PATH_SEPARATOR
,
349 wxT("an absolute path should be given to wxFontMapper::SetConfigPath()") );
351 m_configRootPath
= prefix
;
354 // ----------------------------------------------------------------------------
355 // get config object and path for it
356 // ----------------------------------------------------------------------------
358 wxConfigBase
*wxFontMapperBase::GetConfig()
360 wxConfigBase
*config
= wxConfig::Get(false);
362 // If there is no global configuration, use an internal memory configuration
365 if ( !m_configDummy
)
366 m_configDummy
= new wxMemoryConfig
;
367 config
= m_configDummy
;
369 // FIXME: ideally, we should add keys from dummy config to a real one later,
370 // but it is a low-priority task because typical wxWin application
371 // either doesn't use wxConfig at all or creates wxConfig object in
372 // wxApp::OnInit(), before any real interaction with the user takes
379 const wxString
& wxFontMapperBase::GetConfigPath()
381 if ( !m_configRootPath
)
384 m_configRootPath
= GetDefaultConfigPath();
387 return m_configRootPath
;
390 // ----------------------------------------------------------------------------
392 // ----------------------------------------------------------------------------
394 bool wxFontMapperBase::ChangePath(const wxString
& pathNew
, wxString
*pathOld
)
396 wxConfigBase
*config
= GetConfig();
400 *pathOld
= config
->GetPath();
402 wxString path
= GetConfigPath();
403 if ( path
.empty() || path
.Last() != wxCONFIG_PATH_SEPARATOR
)
405 path
+= wxCONFIG_PATH_SEPARATOR
;
408 wxASSERT_MSG( !pathNew
|| (pathNew
[0] != wxCONFIG_PATH_SEPARATOR
),
409 wxT("should be a relative path") );
413 config
->SetPath(path
);
418 void wxFontMapperBase::RestorePath(const wxString
& pathOld
)
420 GetConfig()->SetPath(pathOld
);
425 // ----------------------------------------------------------------------------
426 // charset/encoding correspondence
427 // ----------------------------------------------------------------------------
430 wxFontMapperBase::CharsetToEncoding(const wxString
& charset
,
431 bool WXUNUSED(interactive
))
433 int enc
= NonInteractiveCharsetToEncoding(charset
);
434 if ( enc
== wxFONTENCODING_UNKNOWN
)
436 // we should return wxFONTENCODING_SYSTEM from here for unknown
438 enc
= wxFONTENCODING_SYSTEM
;
441 return (wxFontEncoding
)enc
;
445 wxFontMapperBase::NonInteractiveCharsetToEncoding(const wxString
& charset
)
447 wxFontEncoding encoding
= wxFONTENCODING_SYSTEM
;
449 // we're going to modify it, make a copy
450 wxString cs
= charset
;
452 #if wxUSE_CONFIG && wxUSE_FILECONFIG
453 // first try the user-defined settings
454 wxFontMapperPathChanger
path(this, FONTMAPPER_CHARSET_PATH
);
457 wxConfigBase
*config
= GetConfig();
459 // do we have an encoding for this charset?
460 long value
= config
->Read(charset
, -1l);
463 if ( value
== wxFONTENCODING_UNKNOWN
)
465 // don't try to find it, in particular don't ask the user
469 if ( value
>= 0 && value
<= wxFONTENCODING_MAX
)
471 encoding
= (wxFontEncoding
)value
;
475 wxLogDebug(wxT("corrupted config data: invalid encoding %ld for charset '%s' ignored"),
476 value
, charset
.c_str());
480 if ( encoding
== wxFONTENCODING_SYSTEM
)
482 // may be we have an alias?
483 config
->SetPath(FONTMAPPER_CHARSET_ALIAS_PATH
);
485 wxString alias
= config
->Read(charset
);
486 if ( !alias
.empty() )
488 // yes, we do - use it instead
493 #endif // wxUSE_CONFIG
495 // if didn't find it there, try to recognize it ourselves
496 if ( encoding
== wxFONTENCODING_SYSTEM
)
502 // discard the optional quotes
505 if ( cs
[0u] == _T('"') && cs
.Last() == _T('"') )
507 cs
= wxString(cs
.c_str(), cs
.length() - 1);
511 // check for known encoding name
512 const wxFontEncoding e
= GetEncodingFromName(cs
);
513 if ( e
!= wxFONTENCODING_MAX
)
516 // deal with general encoding names of the form FOO-xxx
519 if ( cs
.Left(3) == wxT("ISO") )
521 // the dash is optional (or, to be exact, it is not, but many
522 // broken programs "forget" it in the output they generate)
523 const wxChar
*p
= cs
.c_str() + 3;
524 if ( *p
== wxT('-') )
528 if ( wxSscanf(p
, wxT("8859-%u"), &value
) == 1 )
530 // make it 0 based and check that it is strictly positive in
531 // the process (no such thing as iso8859-0 encoding)
532 if ( (value
-- > 0) &&
533 (value
< wxFONTENCODING_ISO8859_MAX
-
534 wxFONTENCODING_ISO8859_1
) )
536 // it's a valid ISO8859 encoding
537 value
+= wxFONTENCODING_ISO8859_1
;
538 encoding
= (wxFontEncoding
)value
;
542 else if ( cs
.Left(4) == wxT("8859") )
544 const wxChar
*p
= cs
.c_str();
547 if ( wxSscanf(p
, wxT("8859-%u"), &value
) == 1 )
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
) )
555 // it's a valid ISO8859 encoding
556 value
+= wxFONTENCODING_ISO8859_1
;
557 encoding
= (wxFontEncoding
)value
;
561 else // check for Windows charsets
564 if ( cs
.Left(7) == wxT("WINDOWS") )
568 else if ( cs
.Left(2) == wxT("CP") )
572 else // not a Windows encoding
579 const wxChar
*p
= cs
.c_str() + len
;
580 if ( *p
== wxT('-') )
584 if ( wxSscanf(p
, wxT("%u"), &value
) == 1 )
589 if ( value
< wxFONTENCODING_CP12_MAX
-
590 wxFONTENCODING_CP1250
)
592 // a valid Windows code page
593 value
+= wxFONTENCODING_CP1250
;
594 encoding
= (wxFontEncoding
)value
;
601 encoding
= wxFONTENCODING_CP866
;
605 encoding
= wxFONTENCODING_CP874
;
609 encoding
= wxFONTENCODING_CP932
;
613 encoding
= wxFONTENCODING_CP936
;
617 encoding
= wxFONTENCODING_CP949
;
621 encoding
= wxFONTENCODING_CP950
;
634 size_t wxFontMapperBase::GetSupportedEncodingsCount()
636 return WXSIZEOF(gs_encodings
);
640 wxFontEncoding
wxFontMapperBase::GetEncoding(size_t n
)
642 wxCHECK_MSG( n
< WXSIZEOF(gs_encodings
), wxFONTENCODING_SYSTEM
,
643 _T("wxFontMapper::GetEncoding(): invalid index") );
645 return gs_encodings
[n
];
649 wxString
wxFontMapperBase::GetEncodingDescription(wxFontEncoding encoding
)
651 if ( encoding
== wxFONTENCODING_DEFAULT
)
653 return _("Default encoding");
656 const size_t count
= WXSIZEOF(gs_encodingDescs
);
658 for ( size_t i
= 0; i
< count
; i
++ )
660 if ( gs_encodings
[i
] == encoding
)
662 return wxGetTranslation(gs_encodingDescs
[i
]);
667 str
.Printf(_("Unknown encoding (%d)"), encoding
);
673 wxString
wxFontMapperBase::GetEncodingName(wxFontEncoding encoding
)
675 if ( encoding
== wxFONTENCODING_DEFAULT
)
680 const size_t count
= WXSIZEOF(gs_encodingNames
);
682 for ( size_t i
= 0; i
< count
; i
++ )
684 if ( gs_encodings
[i
] == encoding
)
686 return gs_encodingNames
[i
][0];
691 str
.Printf(_("unknown-%d"), encoding
);
697 const wxChar
** wxFontMapperBase::GetAllEncodingNames(wxFontEncoding encoding
)
699 static const wxChar
* dummy
[] = { NULL
};
701 for ( size_t i
= 0; i
< WXSIZEOF(gs_encodingNames
); i
++ )
703 if ( gs_encodings
[i
] == encoding
)
705 return gs_encodingNames
[i
];
713 wxFontEncoding
wxFontMapperBase::GetEncodingFromName(const wxString
& name
)
715 const size_t count
= WXSIZEOF(gs_encodingNames
);
717 // many charsets use hyphens in their names but some systems use the
718 // same names without hyphens (e.g. "UTF-8" and "UTF8" are both common)
719 // so to avoid bloating gs_encodingNames array too much recognize both
720 // versions with and without hyphens here
721 wxString
nameNoHyphens(name
);
722 if ( !nameNoHyphens
.Replace(_T("-"), _T("")) )
724 // no replacement has been done, no need to compare twice
725 nameNoHyphens
.clear();
729 for ( size_t i
= 0; i
< count
; i
++ )
731 for ( const wxChar
** encName
= gs_encodingNames
[i
]; *encName
; ++encName
)
733 if ( name
.CmpNoCase(*encName
) == 0 ||
734 (!nameNoHyphens
.empty() &&
735 nameNoHyphens
.CmpNoCase(*encName
) == 0) )
737 return gs_encodings
[i
];
742 return wxFONTENCODING_MAX
;
745 #endif // wxUSE_FONTMAP