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 // Licence: wxWindows licence
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 const 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
,
83 wxFONTENCODING_CP1250
,
84 wxFONTENCODING_CP1251
,
85 wxFONTENCODING_CP1252
,
86 wxFONTENCODING_CP1253
,
87 wxFONTENCODING_CP1254
,
88 wxFONTENCODING_CP1255
,
89 wxFONTENCODING_CP1256
,
90 wxFONTENCODING_CP1257
,
94 wxFONTENCODING_UTF16BE
,
95 wxFONTENCODING_UTF16LE
,
96 wxFONTENCODING_UTF32BE
,
97 wxFONTENCODING_UTF32LE
,
98 wxFONTENCODING_EUC_JP
,
99 wxFONTENCODING_DEFAULT
,
101 wxFONTENCODING_SHIFT_JIS
,
102 wxFONTENCODING_GB2312
,
103 wxFONTENCODING_ISO2022_JP
,
105 wxFONTENCODING_MACROMAN
,
106 wxFONTENCODING_MACJAPANESE
,
107 wxFONTENCODING_MACCHINESETRAD
,
108 wxFONTENCODING_MACKOREAN
,
109 wxFONTENCODING_MACARABIC
,
110 wxFONTENCODING_MACHEBREW
,
111 wxFONTENCODING_MACGREEK
,
112 wxFONTENCODING_MACCYRILLIC
,
113 wxFONTENCODING_MACDEVANAGARI
,
114 wxFONTENCODING_MACGURMUKHI
,
115 wxFONTENCODING_MACGUJARATI
,
116 wxFONTENCODING_MACORIYA
,
117 wxFONTENCODING_MACBENGALI
,
118 wxFONTENCODING_MACTAMIL
,
119 wxFONTENCODING_MACTELUGU
,
120 wxFONTENCODING_MACKANNADA
,
121 wxFONTENCODING_MACMALAJALAM
,
122 wxFONTENCODING_MACSINHALESE
,
123 wxFONTENCODING_MACBURMESE
,
124 wxFONTENCODING_MACKHMER
,
125 wxFONTENCODING_MACTHAI
,
126 wxFONTENCODING_MACLAOTIAN
,
127 wxFONTENCODING_MACGEORGIAN
,
128 wxFONTENCODING_MACARMENIAN
,
129 wxFONTENCODING_MACCHINESESIMP
,
130 wxFONTENCODING_MACTIBETAN
,
131 wxFONTENCODING_MACMONGOLIAN
,
132 wxFONTENCODING_MACETHIOPIC
,
133 wxFONTENCODING_MACCENTRALEUR
,
134 wxFONTENCODING_MACVIATNAMESE
,
135 wxFONTENCODING_MACARABICEXT
,
136 wxFONTENCODING_MACSYMBOL
,
137 wxFONTENCODING_MACDINGBATS
,
138 wxFONTENCODING_MACTURKISH
,
139 wxFONTENCODING_MACCROATIAN
,
140 wxFONTENCODING_MACICELANDIC
,
141 wxFONTENCODING_MACROMANIAN
,
142 wxFONTENCODING_MACCELTIC
,
143 wxFONTENCODING_MACGAELIC
,
144 wxFONTENCODING_MACKEYBOARD
147 // the descriptions for them
148 static const char* const gs_encodingDescs
[] =
150 wxTRANSLATE( "Western European (ISO-8859-1)" ),
151 wxTRANSLATE( "Central European (ISO-8859-2)" ),
152 wxTRANSLATE( "Esperanto (ISO-8859-3)" ),
153 wxTRANSLATE( "Baltic (old) (ISO-8859-4)" ),
154 wxTRANSLATE( "Cyrillic (ISO-8859-5)" ),
155 wxTRANSLATE( "Arabic (ISO-8859-6)" ),
156 wxTRANSLATE( "Greek (ISO-8859-7)" ),
157 wxTRANSLATE( "Hebrew (ISO-8859-8)" ),
158 wxTRANSLATE( "Turkish (ISO-8859-9)" ),
159 wxTRANSLATE( "Nordic (ISO-8859-10)" ),
160 wxTRANSLATE( "Thai (ISO-8859-11)" ),
161 wxTRANSLATE( "Indian (ISO-8859-12)" ),
162 wxTRANSLATE( "Baltic (ISO-8859-13)" ),
163 wxTRANSLATE( "Celtic (ISO-8859-14)" ),
164 wxTRANSLATE( "Western European with Euro (ISO-8859-15)" ),
165 wxTRANSLATE( "KOI8-R" ),
166 wxTRANSLATE( "KOI8-U" ),
167 wxTRANSLATE( "Windows/DOS OEM Cyrillic (CP 866)" ),
168 wxTRANSLATE( "Windows Thai (CP 874)" ),
169 wxTRANSLATE( "Windows Japanese (CP 932)" ),
170 wxTRANSLATE( "Windows Chinese Simplified (CP 936)" ),
171 wxTRANSLATE( "Windows Korean (CP 949)" ),
172 wxTRANSLATE( "Windows Chinese Traditional (CP 950)" ),
173 wxTRANSLATE( "Windows Central European (CP 1250)" ),
174 wxTRANSLATE( "Windows Cyrillic (CP 1251)" ),
175 wxTRANSLATE( "Windows Western European (CP 1252)" ),
176 wxTRANSLATE( "Windows Greek (CP 1253)" ),
177 wxTRANSLATE( "Windows Turkish (CP 1254)" ),
178 wxTRANSLATE( "Windows Hebrew (CP 1255)" ),
179 wxTRANSLATE( "Windows Arabic (CP 1256)" ),
180 wxTRANSLATE( "Windows Baltic (CP 1257)" ),
181 wxTRANSLATE( "Windows/DOS OEM (CP 437)" ),
182 wxTRANSLATE( "Unicode 7 bit (UTF-7)" ),
183 wxTRANSLATE( "Unicode 8 bit (UTF-8)" ),
184 #ifdef WORDS_BIGENDIAN
185 wxTRANSLATE( "Unicode 16 bit (UTF-16)" ),
186 wxTRANSLATE( "Unicode 16 bit Little Endian (UTF-16LE)" ),
187 wxTRANSLATE( "Unicode 32 bit (UTF-32)" ),
188 wxTRANSLATE( "Unicode 32 bit Little Endian (UTF-32LE)" ),
189 #else // WORDS_BIGENDIAN
190 wxTRANSLATE( "Unicode 16 bit Big Endian (UTF-16BE)" ),
191 wxTRANSLATE( "Unicode 16 bit (UTF-16)" ),
192 wxTRANSLATE( "Unicode 32 bit Big Endian (UTF-32BE)" ),
193 wxTRANSLATE( "Unicode 32 bit (UTF-32)" ),
194 #endif // WORDS_BIGENDIAN
195 wxTRANSLATE( "Extended Unix Codepage for Japanese (EUC-JP)" ),
196 wxTRANSLATE( "US-ASCII" ),
197 wxTRANSLATE( "BIG5" ),
198 wxTRANSLATE( "SHIFT-JIS" ),
199 wxTRANSLATE( "GB-2312" ),
200 wxTRANSLATE( "ISO-2022-JP" ),
202 wxTRANSLATE( "MacRoman" ),
203 wxTRANSLATE( "MacJapanese" ),
204 wxTRANSLATE( "MacChineseTrad" ),
205 wxTRANSLATE( "MacKorean" ),
206 wxTRANSLATE( "MacArabic" ),
207 wxTRANSLATE( "MacHebrew" ),
208 wxTRANSLATE( "MacGreek" ),
209 wxTRANSLATE( "MacCyrillic" ),
210 wxTRANSLATE( "MacDevanagari" ),
211 wxTRANSLATE( "MacGurmukhi" ),
212 wxTRANSLATE( "MacGujarati" ),
213 wxTRANSLATE( "MacOriya" ),
214 wxTRANSLATE( "MacBengali" ),
215 wxTRANSLATE( "MacTamil" ),
216 wxTRANSLATE( "MacTelugu" ),
217 wxTRANSLATE( "MacKannada" ),
218 wxTRANSLATE( "MacMalayalam" ),
219 wxTRANSLATE( "MacSinhalese" ),
220 wxTRANSLATE( "MacBurmese" ),
221 wxTRANSLATE( "MacKhmer" ),
222 wxTRANSLATE( "MacThai" ),
223 wxTRANSLATE( "MacLaotian" ),
224 wxTRANSLATE( "MacGeorgian" ),
225 wxTRANSLATE( "MacArmenian" ),
226 wxTRANSLATE( "MacChineseSimp" ),
227 wxTRANSLATE( "MacTibetan" ),
228 wxTRANSLATE( "MacMongolian" ),
229 wxTRANSLATE( "MacEthiopic" ),
230 wxTRANSLATE( "MacCentralEurRoman" ),
231 wxTRANSLATE( "MacVietnamese" ),
232 wxTRANSLATE( "MacExtArabic" ),
233 wxTRANSLATE( "MacSymbol" ),
234 wxTRANSLATE( "MacDingbats" ),
235 wxTRANSLATE( "MacTurkish" ),
236 wxTRANSLATE( "MacCroatian" ),
237 wxTRANSLATE( "MacIcelandic" ),
238 wxTRANSLATE( "MacRomanian" ),
239 wxTRANSLATE( "MacCeltic" ),
240 wxTRANSLATE( "MacGaelic" ),
241 wxTRANSLATE( "MacKeyboardGlyphs" )
244 // and the internal names (these are not translated on purpose!)
245 static const wxChar
* const gs_encodingNames
[WXSIZEOF(gs_encodingDescs
)][9] =
247 // names from the columns correspond to these OS:
248 // Linux Solaris and IRIX HP-UX AIX
249 { wxT("ISO-8859-1"), wxT("ISO8859-1"), wxT("iso88591"), wxT("8859-1"), wxT("iso_8859_1"), NULL
},
250 { wxT("ISO-8859-2"), wxT("ISO8859-2"), wxT("iso88592"), wxT("8859-2"), NULL
},
251 { wxT("ISO-8859-3"), wxT("ISO8859-3"), wxT("iso88593"), wxT("8859-3"), NULL
},
252 { wxT("ISO-8859-4"), wxT("ISO8859-4"), wxT("iso88594"), wxT("8859-4"), NULL
},
253 { wxT("ISO-8859-5"), wxT("ISO8859-5"), wxT("iso88595"), wxT("8859-5"), NULL
},
254 { wxT("ISO-8859-6"), wxT("ISO8859-6"), wxT("iso88596"), wxT("8859-6"), NULL
},
255 { wxT("ISO-8859-7"), wxT("ISO8859-7"), wxT("iso88597"), wxT("8859-7"), NULL
},
256 { wxT("ISO-8859-8"), wxT("ISO8859-8"), wxT("iso88598"), wxT("8859-8"), NULL
},
257 { wxT("ISO-8859-9"), wxT("ISO8859-9"), wxT("iso88599"), wxT("8859-9"), NULL
},
258 { wxT("ISO-8859-10"), wxT("ISO8859-10"), wxT("iso885910"), wxT("8859-10"), NULL
},
259 { wxT("ISO-8859-11"), wxT("ISO8859-11"), wxT("iso885911"), wxT("8859-11"), NULL
},
260 { wxT("ISO-8859-12"), wxT("ISO8859-12"), wxT("iso885912"), wxT("8859-12"), NULL
},
261 { wxT("ISO-8859-13"), wxT("ISO8859-13"), wxT("iso885913"), wxT("8859-13"), NULL
},
262 { wxT("ISO-8859-14"), wxT("ISO8859-14"), wxT("iso885914"), wxT("8859-14"), NULL
},
263 { wxT("ISO-8859-15"), wxT("ISO8859-15"), wxT("iso885915"), wxT("8859-15"), NULL
},
265 // although koi8-ru is not strictly speaking the same as koi8-r,
266 // they are similar enough to make mapping it to koi8 better than
267 // not recognizing it at all
268 { wxT( "KOI8-R" ), wxT( "KOI8-RU" ), NULL
},
269 { wxT( "KOI8-U" ), NULL
},
271 { wxT( "WINDOWS-866" ), wxT( "CP866" ), NULL
},
273 { wxT( "WINDOWS-874" ), wxT( "CP874" ), wxT( "MS874" ), wxT( "IBM-874" ), NULL
},
274 { wxT( "WINDOWS-932" ), wxT( "CP932" ), wxT( "MS932" ), wxT( "IBM-932" ), NULL
},
275 { wxT( "WINDOWS-936" ), wxT( "CP936" ), wxT( "MS936" ), wxT( "IBM-936" ), NULL
},
276 { wxT( "WINDOWS-949" ), wxT( "CP949" ), wxT( "MS949" ), wxT( "IBM-949" ), wxT( "EUC-KR" ), wxT( "eucKR" ), wxT( "euc_kr" ), NULL
},
277 { wxT( "WINDOWS-950" ), wxT( "CP950" ), wxT( "MS950" ), wxT( "IBM-950" ), NULL
},
278 { wxT( "WINDOWS-1250" ),wxT( "CP1250" ),wxT( "MS1250" ),wxT( "IBM-1250" ),NULL
},
279 { wxT( "WINDOWS-1251" ),wxT( "CP1251" ),wxT( "MS1251" ),wxT( "IBM-1251" ),NULL
},
280 { wxT( "WINDOWS-1252" ),wxT( "CP1252" ),wxT( "MS1252" ),wxT( "IBM-1252" ),NULL
},
281 { wxT( "WINDOWS-1253" ),wxT( "CP1253" ),wxT( "MS1253" ),wxT( "IBM-1253" ),NULL
},
282 { wxT( "WINDOWS-1254" ),wxT( "CP1254" ),wxT( "MS1254" ),wxT( "IBM-1254" ),NULL
},
283 { wxT( "WINDOWS-1255" ),wxT( "CP1255" ),wxT( "MS1255" ),wxT( "IBM-1255" ),NULL
},
284 { wxT( "WINDOWS-1256" ),wxT( "CP1256" ),wxT( "MS1256" ),wxT( "IBM-1256" ),NULL
},
285 { wxT( "WINDOWS-1257" ),wxT( "CP1257" ),wxT( "MS1257" ),wxT( "IBM-1257" ),NULL
},
286 { wxT( "WINDOWS-437" ), wxT( "CP437" ), wxT( "MS437" ), wxT( "IBM-437" ), NULL
},
288 { wxT( "UTF-7" ), wxT("UTF7"), NULL
},
289 { wxT( "UTF-8" ), wxT("UTF8"), NULL
},
290 #ifdef WORDS_BIGENDIAN
291 { wxT( "UTF-16BE" ), wxT("UTF16BE"), wxT("UCS-2BE"), wxT("UCS2BE"), wxT("UTF-16"), wxT("UTF16"), wxT("UCS-2"), wxT("UCS2"), NULL
},
292 { wxT( "UTF-16LE" ), wxT("UTF16LE"), wxT("UCS-2LE"), wxT("UCS2LE"), NULL
},
293 { wxT( "UTF-32BE" ), wxT("UTF32BE"), wxT("UCS-4BE" ), wxT("UTF-32"), wxT("UTF32"), wxT("UCS-4"), wxT("UCS4"), NULL
},
294 { wxT( "UTF-32LE" ), wxT("UTF32LE"), wxT("UCS-4LE"), wxT("UCS4LE"), NULL
},
295 #else // WORDS_BIGENDIAN
296 { wxT("UTF-16BE"), wxT("UTF16BE"), wxT("UCS-2BE"), wxT("UCS2BE"), NULL
},
297 { wxT("UTF-16LE"), wxT("UTF16LE"), wxT("UCS-2LE"), wxT("UTF-16"), wxT("UTF16"), wxT("UCS-2"), wxT("UCS2"), NULL
},
298 { wxT("UTF-32BE"), wxT("UTF32BE"), wxT("UCS-4BE"), wxT("UCS4BE"), NULL
},
299 { wxT("UTF-32LE"), wxT("UTF32LE"), wxT("UCS-4LE"), wxT("UCS4LE"), wxT("UTF-32"), wxT("UTF32"), wxT("UCS-4"), wxT("UCS4"), NULL
},
300 #endif // WORDS_BIGENDIAN
302 { wxT( "EUC-JP" ), wxT( "eucJP" ), wxT( "euc_jp" ), wxT( "IBM-eucJP" ), NULL
},
304 // 646 is for Solaris, roman8 -- for HP-UX
305 { wxT( "US-ASCII" ), wxT( "ASCII" ), wxT("C"), wxT("POSIX"), wxT("ANSI_X3.4-1968"),
306 wxT("646"), wxT("roman8"), wxT( "" ), NULL
},
308 { wxT( "BIG5" ), wxT("big5"), NULL
},
309 { wxT( "SJIS" ), wxT( "SHIFT-JIS" ), wxT( "SHIFT_JIS" ), NULL
},
310 { wxT( "GB2312" ), NULL
},
311 { wxT( "ISO-2022-JP" ), NULL
},
314 { wxT( "MacRoman" ), NULL
},
315 { wxT( "MacJapanese" ), NULL
},
316 { wxT( "MacChineseTrad" ), NULL
},
317 { wxT( "MacKorean" ), NULL
},
318 { wxT( "MacArabic" ), NULL
},
319 { wxT( "MacHebrew" ), NULL
},
320 { wxT( "MacGreek" ), NULL
},
321 { wxT( "MacCyrillic" ), NULL
},
322 { wxT( "MacDevanagari" ), NULL
},
323 { wxT( "MacGurmukhi" ), NULL
},
324 { wxT( "MacGujarati" ), NULL
},
325 { wxT( "MacOriya" ), NULL
},
326 { wxT( "MacBengali" ), NULL
},
327 { wxT( "MacTamil" ), NULL
},
328 { wxT( "MacTelugu" ), NULL
},
329 { wxT( "MacKannada" ), NULL
},
330 { wxT( "MacMalayalam" ), NULL
},
331 { wxT( "MacSinhalese" ), NULL
},
332 { wxT( "MacBurmese" ), NULL
},
333 { wxT( "MacKhmer" ), NULL
},
334 { wxT( "MacThai" ), NULL
},
335 { wxT( "MacLaotian" ), NULL
},
336 { wxT( "MacGeorgian" ), NULL
},
337 { wxT( "MacArmenian" ), NULL
},
338 { wxT( "MacChineseSimp" ), NULL
},
339 { wxT( "MacTibetan" ), NULL
},
340 { wxT( "MacMongolian" ), NULL
},
341 { wxT( "MacEthiopic" ), NULL
},
342 { wxT( "MacCentralEurRoman" ), NULL
},
343 { wxT( "MacVietnamese" ), NULL
},
344 { wxT( "MacExtArabic" ), NULL
},
345 { wxT( "MacSymbol" ), NULL
},
346 { wxT( "MacDingbats" ), NULL
},
347 { wxT( "MacTurkish" ), NULL
},
348 { wxT( "MacCroatian" ), NULL
},
349 { wxT( "MacIcelandic" ), NULL
},
350 { wxT( "MacRomanian" ), NULL
},
351 { wxT( "MacCeltic" ), NULL
},
352 { wxT( "MacGaelic" ), NULL
},
353 { wxT( "MacKeyboardGlyphs" ), NULL
}
356 wxCOMPILE_TIME_ASSERT( WXSIZEOF(gs_encodingDescs
) == WXSIZEOF(gs_encodings
), EncodingsArraysNotInSync
);
357 wxCOMPILE_TIME_ASSERT( WXSIZEOF(gs_encodingNames
) == WXSIZEOF(gs_encodings
), EncodingsArraysNotInSync
);
359 // ----------------------------------------------------------------------------
361 // ----------------------------------------------------------------------------
363 // clean up the font mapper object
364 class wxFontMapperModule
: public wxModule
367 wxFontMapperModule() : wxModule() { }
369 virtual bool OnInit()
371 // a dummy wxFontMapperBase object could have been created during the
372 // program startup before wxApp was created, we have to delete it to
373 // allow creating the real font mapper next time it is needed now that
374 // we can create it (when the modules are initialized, wxApp object
376 wxFontMapperBase
*fm
= wxFontMapperBase::Get();
377 if ( fm
&& fm
->IsDummy() )
378 wxFontMapperBase::Reset();
383 virtual void OnExit()
385 wxFontMapperBase::Reset();
388 DECLARE_DYNAMIC_CLASS(wxFontMapperModule
)
391 IMPLEMENT_DYNAMIC_CLASS(wxFontMapperModule
, wxModule
)
394 // ============================================================================
395 // wxFontMapperBase implementation
396 // ============================================================================
398 wxFontMapper
*wxFontMapperBase::sm_instance
= NULL
;
400 // ----------------------------------------------------------------------------
402 // ----------------------------------------------------------------------------
404 wxFontMapperBase::wxFontMapperBase()
406 #if wxUSE_CONFIG && wxUSE_FILECONFIG
407 m_configDummy
= NULL
;
408 #endif // wxUSE_CONFIG
411 wxFontMapperBase::~wxFontMapperBase()
413 #if wxUSE_CONFIG && wxUSE_FILECONFIG
415 delete m_configDummy
;
416 #endif // wxUSE_CONFIG
420 wxFontMapperBase
*wxFontMapperBase::Get()
424 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
427 sm_instance
= traits
->CreateFontMapper();
429 wxASSERT_MSG( sm_instance
,
430 wxT("wxAppTraits::CreateFontMapper() failed") );
435 // last resort: we must create something because the existing code
436 // relies on always having a valid font mapper object
437 sm_instance
= (wxFontMapper
*)new wxFontMapperBase
;
441 return (wxFontMapperBase
*)sm_instance
;
445 wxFontMapper
*wxFontMapperBase::Set(wxFontMapper
*mapper
)
447 wxFontMapper
*old
= sm_instance
;
448 sm_instance
= mapper
;
453 void wxFontMapperBase::Reset()
457 // we need a cast as wxFontMapper is not fully declared here and so the
458 // compiler can't know that it derives from wxFontMapperBase (but
459 // run-time behaviour will be correct because the dtor is virtual)
460 delete (wxFontMapperBase
*)sm_instance
;
465 #if wxUSE_CONFIG && wxUSE_FILECONFIG
467 // ----------------------------------------------------------------------------
468 // config usage customisation
469 // ----------------------------------------------------------------------------
472 static wxString
gs_defaultConfigPath(FONTMAPPER_ROOT_PATH
);
475 const wxString
& wxFontMapperBase::GetDefaultConfigPath()
477 // NB: we return const wxString& and not wxString for compatibility
478 // with 2.8 that returned const wxChar*
479 return gs_defaultConfigPath
;
482 void wxFontMapperBase::SetConfigPath(const wxString
& prefix
)
484 wxCHECK_RET( !prefix
.empty() && prefix
[0] == wxCONFIG_PATH_SEPARATOR
,
485 wxT("an absolute path should be given to wxFontMapper::SetConfigPath()") );
487 m_configRootPath
= prefix
;
490 // ----------------------------------------------------------------------------
491 // get config object and path for it
492 // ----------------------------------------------------------------------------
494 wxConfigBase
*wxFontMapperBase::GetConfig()
496 wxConfigBase
*config
= wxConfig::Get(false);
498 // If there is no global configuration, use an internal memory configuration
501 if ( !m_configDummy
)
502 m_configDummy
= new wxMemoryConfig
;
503 config
= m_configDummy
;
505 // FIXME: ideally, we should add keys from dummy config to a real one later,
506 // but it is a low-priority task because typical wxWin application
507 // either doesn't use wxConfig at all or creates wxConfig object in
508 // wxApp::OnInit(), before any real interaction with the user takes
515 const wxString
& wxFontMapperBase::GetConfigPath()
517 if ( !m_configRootPath
)
520 m_configRootPath
= GetDefaultConfigPath();
523 return m_configRootPath
;
526 // ----------------------------------------------------------------------------
528 // ----------------------------------------------------------------------------
530 bool wxFontMapperBase::ChangePath(const wxString
& pathNew
, wxString
*pathOld
)
532 wxConfigBase
*config
= GetConfig();
536 *pathOld
= config
->GetPath();
538 wxString path
= GetConfigPath();
539 if ( path
.empty() || path
.Last() != wxCONFIG_PATH_SEPARATOR
)
541 path
+= wxCONFIG_PATH_SEPARATOR
;
544 wxASSERT_MSG( !pathNew
|| (pathNew
[0] != wxCONFIG_PATH_SEPARATOR
),
545 wxT("should be a relative path") );
549 config
->SetPath(path
);
554 void wxFontMapperBase::RestorePath(const wxString
& pathOld
)
556 GetConfig()->SetPath(pathOld
);
561 // ----------------------------------------------------------------------------
562 // charset/encoding correspondence
563 // ----------------------------------------------------------------------------
566 wxFontMapperBase::CharsetToEncoding(const wxString
& charset
,
567 bool WXUNUSED(interactive
))
569 int enc
= NonInteractiveCharsetToEncoding(charset
);
570 if ( enc
== wxFONTENCODING_UNKNOWN
)
572 // we should return wxFONTENCODING_SYSTEM from here for unknown
574 enc
= wxFONTENCODING_SYSTEM
;
577 return (wxFontEncoding
)enc
;
581 wxFontMapperBase::NonInteractiveCharsetToEncoding(const wxString
& charset
)
583 wxFontEncoding encoding
= wxFONTENCODING_SYSTEM
;
585 // we're going to modify it, make a copy
586 wxString cs
= charset
;
588 #if wxUSE_CONFIG && wxUSE_FILECONFIG
589 // first try the user-defined settings
590 wxFontMapperPathChanger
path(this, FONTMAPPER_CHARSET_PATH
);
593 wxConfigBase
*config
= GetConfig();
595 // do we have an encoding for this charset?
596 long value
= config
->Read(charset
, -1l);
599 if ( value
== wxFONTENCODING_UNKNOWN
)
601 // don't try to find it, in particular don't ask the user
605 if ( value
>= 0 && value
<= wxFONTENCODING_MAX
)
607 encoding
= (wxFontEncoding
)value
;
611 wxLogDebug(wxT("corrupted config data: invalid encoding %ld for charset '%s' ignored"),
612 value
, charset
.c_str());
616 if ( encoding
== wxFONTENCODING_SYSTEM
)
618 // may be we have an alias?
619 config
->SetPath(FONTMAPPER_CHARSET_ALIAS_PATH
);
621 wxString alias
= config
->Read(charset
);
622 if ( !alias
.empty() )
624 // yes, we do - use it instead
629 #endif // wxUSE_CONFIG
631 // if didn't find it there, try to recognize it ourselves
632 if ( encoding
== wxFONTENCODING_SYSTEM
)
638 // discard the optional quotes
641 if ( cs
[0u] == wxT('"') && cs
.Last() == wxT('"') )
643 cs
= wxString(cs
.c_str(), cs
.length() - 1);
647 for ( size_t i
= 0; i
< WXSIZEOF(gs_encodingNames
); ++i
)
649 for ( const wxChar
* const* encName
= gs_encodingNames
[i
]; *encName
; ++encName
)
651 if ( cs
.CmpNoCase(*encName
) == 0 )
652 return gs_encodings
[i
];
658 if ( cs
.Left(3) == wxT("ISO") )
660 // the dash is optional (or, to be exact, it is not, but
661 // several broken programs "forget" it)
662 const wxChar
*p
= cs
.c_str() + 3;
663 if ( *p
== wxT('-') )
667 if ( wxSscanf(p
, wxT("8859-%u"), &value
) == 1 )
669 // make it 0 based and check that it is strictly positive in
670 // the process (no such thing as iso8859-0 encoding)
671 if ( (value
-- > 0) &&
672 (value
< wxFONTENCODING_ISO8859_MAX
-
673 wxFONTENCODING_ISO8859_1
) )
675 // it's a valid ISO8859 encoding
676 value
+= wxFONTENCODING_ISO8859_1
;
677 encoding
= (wxFontEncoding
)value
;
681 else if ( cs
.Left(4) == wxT("8859") )
683 const wxChar
*p
= cs
.c_str();
686 if ( wxSscanf(p
, wxT("8859-%u"), &value
) == 1 )
688 // make it 0 based and check that it is strictly positive in
689 // the process (no such thing as iso8859-0 encoding)
690 if ( (value
-- > 0) &&
691 (value
< wxFONTENCODING_ISO8859_MAX
-
692 wxFONTENCODING_ISO8859_1
) )
694 // it's a valid ISO8859 encoding
695 value
+= wxFONTENCODING_ISO8859_1
;
696 encoding
= (wxFontEncoding
)value
;
700 else // check for Windows charsets
703 if ( cs
.Left(7) == wxT("WINDOWS") )
707 else if ( cs
.Left(2) == wxT("CP") )
711 else // not a Windows encoding
718 const wxChar
*p
= cs
.c_str() + len
;
719 if ( *p
== wxT('-') )
723 if ( wxSscanf(p
, wxT("%u"), &value
) == 1 )
728 if ( value
< wxFONTENCODING_CP12_MAX
-
729 wxFONTENCODING_CP1250
)
731 // a valid Windows code page
732 value
+= wxFONTENCODING_CP1250
;
733 encoding
= (wxFontEncoding
)value
;
740 encoding
= wxFONTENCODING_CP866
;
744 encoding
= wxFONTENCODING_CP874
;
748 encoding
= wxFONTENCODING_CP932
;
752 encoding
= wxFONTENCODING_CP936
;
756 encoding
= wxFONTENCODING_CP949
;
760 encoding
= wxFONTENCODING_CP950
;
773 size_t wxFontMapperBase::GetSupportedEncodingsCount()
775 return WXSIZEOF(gs_encodings
);
779 wxFontEncoding
wxFontMapperBase::GetEncoding(size_t n
)
781 wxCHECK_MSG( n
< WXSIZEOF(gs_encodings
), wxFONTENCODING_SYSTEM
,
782 wxT("wxFontMapper::GetEncoding(): invalid index") );
784 return gs_encodings
[n
];
788 wxString
wxFontMapperBase::GetEncodingDescription(wxFontEncoding encoding
)
790 if ( encoding
== wxFONTENCODING_DEFAULT
)
792 return _("Default encoding");
795 const size_t count
= WXSIZEOF(gs_encodingDescs
);
797 for ( size_t i
= 0; i
< count
; i
++ )
799 if ( gs_encodings
[i
] == encoding
)
801 return wxGetTranslation(gs_encodingDescs
[i
]);
806 str
.Printf(_("Unknown encoding (%d)"), encoding
);
812 wxString
wxFontMapperBase::GetEncodingName(wxFontEncoding encoding
)
814 if ( encoding
== wxFONTENCODING_DEFAULT
)
819 const size_t count
= WXSIZEOF(gs_encodingNames
);
821 for ( size_t i
= 0; i
< count
; i
++ )
823 if ( gs_encodings
[i
] == encoding
)
825 return gs_encodingNames
[i
][0];
830 str
.Printf(_("unknown-%d"), encoding
);
836 const wxChar
** wxFontMapperBase::GetAllEncodingNames(wxFontEncoding encoding
)
838 static const wxChar
* const dummy
[] = { NULL
};
840 for ( size_t i
= 0; i
< WXSIZEOF(gs_encodingNames
); i
++ )
842 if ( gs_encodings
[i
] == encoding
)
844 return const_cast<const wxChar
**>(gs_encodingNames
[i
]);
848 return const_cast<const wxChar
**>(dummy
);
852 wxFontEncoding
wxFontMapperBase::GetEncodingFromName(const wxString
& name
)
854 const size_t count
= WXSIZEOF(gs_encodingNames
);
856 for ( size_t i
= 0; i
< count
; i
++ )
858 for ( const wxChar
* const* encName
= gs_encodingNames
[i
]; *encName
; ++encName
)
860 if ( name
.CmpNoCase(*encName
) == 0 )
861 return gs_encodings
[i
];
865 return wxFONTENCODING_MAX
;
868 #endif // wxUSE_FONTMAP