1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/fontutil.cpp
3 // Purpose: font-related helper functions for wxMSW
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "fontutil.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/string.h"
37 #include "wx/fontutil.h"
38 #include "wx/fontmap.h"
39 #include "wx/encinfo.h"
41 #include "wx/tokenzr.h"
43 #include "ATSUnicode.h"
44 #include "TextCommon.h"
45 #include "TextEncodingConverter.h"
47 #include "wx/mac/private.h" // includes mac headers
49 // ============================================================================
51 // ============================================================================
53 // ----------------------------------------------------------------------------
54 // wxNativeEncodingInfo
55 // ----------------------------------------------------------------------------
57 // convert to/from the string representation: format is
60 bool wxNativeEncodingInfo::FromString(const wxString
& s
)
62 wxStringTokenizer
tokenizer(s
, _T(";"));
64 facename
= tokenizer
.GetNextToken();
68 wxString tmp
= tokenizer
.GetNextToken();
71 // default charset (don't use DEFAULT_CHARSET though because of subtle
72 // Windows 9x/NT differences in handling it)
77 if ( wxSscanf(tmp
, _T("%u"), &charset
) != 1 )
79 // should be a number!
87 wxString
wxNativeEncodingInfo::ToString() const
92 s
<< _T(';') << charset
;
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
103 wxNativeEncodingInfo
*info
)
105 wxCHECK_MSG( info
, FALSE
, _T("bad pointer in wxGetNativeFontEncoding") );
107 if ( encoding
== wxFONTENCODING_DEFAULT
)
109 encoding
= wxFont::GetDefaultEncoding();
112 info
->encoding
= encoding
;
117 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
119 return info
.encoding
== wxFont::GetDefaultEncoding() ;
122 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
124 TextEncodingBase enc
= 0 ;
128 case wxFONTENCODING_ISO8859_1
:
129 enc
= kTextEncodingISOLatin1
;
131 case wxFONTENCODING_ISO8859_2
:
132 enc
= kTextEncodingISOLatin2
;
134 case wxFONTENCODING_ISO8859_3
:
135 enc
= kTextEncodingISOLatin3
;
137 case wxFONTENCODING_ISO8859_4
:
138 enc
= kTextEncodingISOLatin4
;
140 case wxFONTENCODING_ISO8859_5
:
141 enc
= kTextEncodingISOLatinCyrillic
;
143 case wxFONTENCODING_ISO8859_6
:
144 enc
= kTextEncodingISOLatinArabic
;
146 case wxFONTENCODING_ISO8859_7
:
147 enc
= kTextEncodingISOLatinGreek
;
149 case wxFONTENCODING_ISO8859_8
:
150 enc
= kTextEncodingISOLatinHebrew
;
152 case wxFONTENCODING_ISO8859_9
:
153 enc
= kTextEncodingISOLatin5
;
155 case wxFONTENCODING_ISO8859_10
:
156 enc
= kTextEncodingISOLatin6
;
158 case wxFONTENCODING_ISO8859_13
:
159 enc
= kTextEncodingISOLatin7
;
161 case wxFONTENCODING_ISO8859_14
:
162 enc
= kTextEncodingISOLatin8
;
164 case wxFONTENCODING_ISO8859_15
:
165 enc
= kTextEncodingISOLatin9
;
168 case wxFONTENCODING_KOI8
:
169 enc
= kTextEncodingKOI8_R
;
171 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
172 enc
= kTextEncodingDOSRussian
;
175 case wxFONTENCODING_BULGARIAN :
179 case wxFONTENCODING_CP437
:
180 enc
=kTextEncodingDOSLatinUS
;
182 case wxFONTENCODING_CP850
:
183 enc
= kTextEncodingDOSLatin1
;
185 case wxFONTENCODING_CP852
:
186 enc
= kTextEncodingDOSLatin2
;
188 case wxFONTENCODING_CP855
:
189 enc
= kTextEncodingDOSCyrillic
;
191 case wxFONTENCODING_CP866
:
192 enc
=kTextEncodingDOSRussian
;
194 case wxFONTENCODING_CP874
:
195 enc
= kTextEncodingDOSThai
;
197 case wxFONTENCODING_CP932
:
198 enc
= kTextEncodingDOSJapanese
;
200 case wxFONTENCODING_CP936
:
201 enc
=kTextEncodingDOSChineseSimplif
;
203 case wxFONTENCODING_CP949
:
204 enc
= kTextEncodingDOSKorean
;
206 case wxFONTENCODING_CP950
:
207 enc
= kTextEncodingDOSChineseTrad
;
210 case wxFONTENCODING_CP1250
:
211 enc
= kTextEncodingWindowsLatin2
;
213 case wxFONTENCODING_CP1251
:
214 enc
=kTextEncodingWindowsCyrillic
;
216 case wxFONTENCODING_CP1252
:
217 enc
=kTextEncodingWindowsLatin1
;
219 case wxFONTENCODING_CP1253
:
220 enc
= kTextEncodingWindowsGreek
;
222 case wxFONTENCODING_CP1254
:
223 enc
= kTextEncodingWindowsLatin5
;
225 case wxFONTENCODING_CP1255
:
226 enc
=kTextEncodingWindowsHebrew
;
228 case wxFONTENCODING_CP1256
:
229 enc
=kTextEncodingWindowsArabic
;
231 case wxFONTENCODING_CP1257
:
232 enc
= kTextEncodingWindowsBalticRim
;
235 case wxFONTENCODING_UTF7
:
236 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
238 case wxFONTENCODING_UTF8
:
239 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
241 case wxFONTENCODING_EUC_JP
:
242 enc
= kTextEncodingEUC_JP
;
244 case wxFONTENCODING_UTF16BE
:
245 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
247 case wxFONTENCODING_UTF16LE
:
248 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
250 case wxFONTENCODING_UTF32BE
:
251 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
253 case wxFONTENCODING_UTF32LE
:
254 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
257 case wxFONTENCODING_MACROMAN
:
258 enc
= kTextEncodingMacRoman
;
260 case wxFONTENCODING_MACJAPANESE
:
261 enc
= kTextEncodingMacJapanese
;
263 case wxFONTENCODING_MACCHINESETRAD
:
264 enc
= kTextEncodingMacChineseTrad
;
266 case wxFONTENCODING_MACKOREAN
:
267 enc
= kTextEncodingMacKorean
;
269 case wxFONTENCODING_MACARABIC
:
270 enc
= kTextEncodingMacArabic
;
272 case wxFONTENCODING_MACHEBREW
:
273 enc
= kTextEncodingMacHebrew
;
275 case wxFONTENCODING_MACGREEK
:
276 enc
= kTextEncodingMacGreek
;
278 case wxFONTENCODING_MACCYRILLIC
:
279 enc
= kTextEncodingMacCyrillic
;
281 case wxFONTENCODING_MACDEVANAGARI
:
282 enc
= kTextEncodingMacDevanagari
;
284 case wxFONTENCODING_MACGURMUKHI
:
285 enc
= kTextEncodingMacGurmukhi
;
287 case wxFONTENCODING_MACGUJARATI
:
288 enc
= kTextEncodingMacGujarati
;
290 case wxFONTENCODING_MACORIYA
:
291 enc
= kTextEncodingMacOriya
;
293 case wxFONTENCODING_MACBENGALI
:
294 enc
= kTextEncodingMacBengali
;
296 case wxFONTENCODING_MACTAMIL
:
297 enc
= kTextEncodingMacTamil
;
299 case wxFONTENCODING_MACTELUGU
:
300 enc
= kTextEncodingMacTelugu
;
302 case wxFONTENCODING_MACKANNADA
:
303 enc
= kTextEncodingMacKannada
;
305 case wxFONTENCODING_MACMALAJALAM
:
306 enc
= kTextEncodingMacMalayalam
;
308 case wxFONTENCODING_MACSINHALESE
:
309 enc
= kTextEncodingMacSinhalese
;
311 case wxFONTENCODING_MACBURMESE
:
312 enc
= kTextEncodingMacBurmese
;
314 case wxFONTENCODING_MACKHMER
:
315 enc
= kTextEncodingMacKhmer
;
317 case wxFONTENCODING_MACTHAI
:
318 enc
= kTextEncodingMacThai
;
320 case wxFONTENCODING_MACLAOTIAN
:
321 enc
= kTextEncodingMacLaotian
;
323 case wxFONTENCODING_MACGEORGIAN
:
324 enc
= kTextEncodingMacGeorgian
;
326 case wxFONTENCODING_MACARMENIAN
:
327 enc
= kTextEncodingMacArmenian
;
329 case wxFONTENCODING_MACCHINESESIMP
:
330 enc
= kTextEncodingMacChineseSimp
;
332 case wxFONTENCODING_MACTIBETAN
:
333 enc
= kTextEncodingMacTibetan
;
335 case wxFONTENCODING_MACMONGOLIAN
:
336 enc
= kTextEncodingMacMongolian
;
338 case wxFONTENCODING_MACETHIOPIC
:
339 enc
= kTextEncodingMacEthiopic
;
341 case wxFONTENCODING_MACCENTRALEUR
:
342 enc
= kTextEncodingMacCentralEurRoman
;
344 case wxFONTENCODING_MACVIATNAMESE
:
345 enc
= kTextEncodingMacVietnamese
;
347 case wxFONTENCODING_MACARABICEXT
:
348 enc
= kTextEncodingMacExtArabic
;
350 case wxFONTENCODING_MACSYMBOL
:
351 enc
= kTextEncodingMacSymbol
;
353 case wxFONTENCODING_MACDINGBATS
:
354 enc
= kTextEncodingMacDingbats
;
356 case wxFONTENCODING_MACTURKISH
:
357 enc
= kTextEncodingMacTurkish
;
359 case wxFONTENCODING_MACCROATIAN
:
360 enc
= kTextEncodingMacCroatian
;
362 case wxFONTENCODING_MACICELANDIC
:
363 enc
= kTextEncodingMacIcelandic
;
365 case wxFONTENCODING_MACROMANIAN
:
366 enc
= kTextEncodingMacRomanian
;
368 case wxFONTENCODING_MACCELTIC
:
369 enc
= kTextEncodingMacCeltic
;
371 case wxFONTENCODING_MACGAELIC
:
372 enc
= kTextEncodingMacGaelic
;
374 case wxFONTENCODING_MACKEYBOARD
:
375 enc
= kTextEncodingMacKeyboardGlyphs
;
381 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
383 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
387 case kTextEncodingISOLatin1
:
388 enc
= wxFONTENCODING_ISO8859_1
;
390 case kTextEncodingISOLatin2
:
391 enc
= wxFONTENCODING_ISO8859_2
;
393 case kTextEncodingISOLatin3
:
394 enc
= wxFONTENCODING_ISO8859_3
;
396 case kTextEncodingISOLatin4
:
397 enc
= wxFONTENCODING_ISO8859_4
;
399 case kTextEncodingISOLatinCyrillic
:
400 enc
= wxFONTENCODING_ISO8859_5
;
402 case kTextEncodingISOLatinArabic
:
403 enc
= wxFONTENCODING_ISO8859_6
;
405 case kTextEncodingISOLatinGreek
:
406 enc
= wxFONTENCODING_ISO8859_7
;
408 case kTextEncodingISOLatinHebrew
:
409 enc
= wxFONTENCODING_ISO8859_8
;
411 case kTextEncodingISOLatin5
:
412 enc
= wxFONTENCODING_ISO8859_9
;
414 case kTextEncodingISOLatin6
:
415 enc
= wxFONTENCODING_ISO8859_10
;
417 case kTextEncodingISOLatin7
:
418 enc
= wxFONTENCODING_ISO8859_13
;
420 case kTextEncodingISOLatin8
:
421 enc
= wxFONTENCODING_ISO8859_14
;
423 case kTextEncodingISOLatin9
:
424 enc
=wxFONTENCODING_ISO8859_15
;
427 case kTextEncodingKOI8_R
:
428 enc
= wxFONTENCODING_KOI8
;
432 enc = wxFONTENCODING_BULGARIAN;
435 casekTextEncodingDOSLatinUS
:
436 enc
= wxFONTENCODING_CP437
;
438 case kTextEncodingDOSLatin1
:
439 enc
= wxFONTENCODING_CP850
;
441 case kTextEncodingDOSLatin2
:
442 enc
=wxFONTENCODING_CP852
;
444 case kTextEncodingDOSCyrillic
:
445 enc
= wxFONTENCODING_CP855
;
447 case kTextEncodingDOSRussian
:
448 enc
= wxFONTENCODING_CP866
;
450 case kTextEncodingDOSThai
:
451 enc
=wxFONTENCODING_CP874
;
453 case kTextEncodingDOSJapanese
:
454 enc
= wxFONTENCODING_CP932
;
456 case kTextEncodingDOSChineseSimplif
:
457 enc
= wxFONTENCODING_CP936
;
459 case kTextEncodingDOSKorean
:
460 enc
= wxFONTENCODING_CP949
;
462 case kTextEncodingDOSChineseTrad
:
463 enc
= wxFONTENCODING_CP950
;
466 case kTextEncodingWindowsLatin2
:
467 enc
= wxFONTENCODING_CP1250
;
469 case kTextEncodingWindowsCyrillic
:
470 enc
= wxFONTENCODING_CP1251
;
472 case kTextEncodingWindowsLatin1
:
473 enc
= wxFONTENCODING_CP1252
;
475 case kTextEncodingWindowsGreek
:
476 enc
= wxFONTENCODING_CP1253
;
478 case kTextEncodingWindowsLatin5
:
479 enc
= wxFONTENCODING_CP1254
;
481 case kTextEncodingWindowsHebrew
:
482 enc
= wxFONTENCODING_CP1255
;
484 case kTextEncodingWindowsArabic
:
485 enc
= wxFONTENCODING_CP1256
;
487 case kTextEncodingWindowsBalticRim
:
488 enc
=wxFONTENCODING_CP1257
;
490 case kTextEncodingEUC_JP
:
491 enc
= wxFONTENCODING_EUC_JP
;
494 case wxFONTENCODING_UTF7 :
495 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
497 case wxFONTENCODING_UTF8 :
498 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
500 case wxFONTENCODING_UTF16BE :
501 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
503 case wxFONTENCODING_UTF16LE :
504 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
506 case wxFONTENCODING_UTF32BE :
507 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
509 case wxFONTENCODING_UTF32LE :
510 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
513 case kTextEncodingMacRoman
:
514 enc
= wxFONTENCODING_MACROMAN
;
516 case kTextEncodingMacJapanese
:
517 enc
= wxFONTENCODING_MACJAPANESE
;
519 case kTextEncodingMacChineseTrad
:
520 enc
= wxFONTENCODING_MACCHINESETRAD
;
522 case kTextEncodingMacKorean
:
523 enc
= wxFONTENCODING_MACKOREAN
;
525 case kTextEncodingMacArabic
:
526 enc
=wxFONTENCODING_MACARABIC
;
528 case kTextEncodingMacHebrew
:
529 enc
= wxFONTENCODING_MACHEBREW
;
531 case kTextEncodingMacGreek
:
532 enc
= wxFONTENCODING_MACGREEK
;
534 case kTextEncodingMacCyrillic
:
535 enc
= wxFONTENCODING_MACCYRILLIC
;
537 case kTextEncodingMacDevanagari
:
538 enc
= wxFONTENCODING_MACDEVANAGARI
;
540 case kTextEncodingMacGurmukhi
:
541 enc
= wxFONTENCODING_MACGURMUKHI
;
543 case kTextEncodingMacGujarati
:
544 enc
= wxFONTENCODING_MACGUJARATI
;
546 case kTextEncodingMacOriya
:
547 enc
=wxFONTENCODING_MACORIYA
;
549 case kTextEncodingMacBengali
:
550 enc
=wxFONTENCODING_MACBENGALI
;
552 case kTextEncodingMacTamil
:
553 enc
= wxFONTENCODING_MACTAMIL
;
555 case kTextEncodingMacTelugu
:
556 enc
= wxFONTENCODING_MACTELUGU
;
558 case kTextEncodingMacKannada
:
559 enc
= wxFONTENCODING_MACKANNADA
;
561 case kTextEncodingMacMalayalam
:
562 enc
= wxFONTENCODING_MACMALAJALAM
;
564 case kTextEncodingMacSinhalese
:
565 enc
= wxFONTENCODING_MACSINHALESE
;
567 case kTextEncodingMacBurmese
:
568 enc
= wxFONTENCODING_MACBURMESE
;
570 case kTextEncodingMacKhmer
:
571 enc
= wxFONTENCODING_MACKHMER
;
573 case kTextEncodingMacThai
:
574 enc
= wxFONTENCODING_MACTHAI
;
576 case kTextEncodingMacLaotian
:
577 enc
= wxFONTENCODING_MACLAOTIAN
;
579 case kTextEncodingMacGeorgian
:
580 enc
= wxFONTENCODING_MACGEORGIAN
;
582 case kTextEncodingMacArmenian
:
583 enc
= wxFONTENCODING_MACARMENIAN
;
585 case kTextEncodingMacChineseSimp
:
586 enc
= wxFONTENCODING_MACCHINESESIMP
;
588 case kTextEncodingMacTibetan
:
589 enc
= wxFONTENCODING_MACTIBETAN
;
591 case kTextEncodingMacMongolian
:
592 enc
= wxFONTENCODING_MACMONGOLIAN
;
594 case kTextEncodingMacEthiopic
:
595 enc
= wxFONTENCODING_MACETHIOPIC
;
597 case kTextEncodingMacCentralEurRoman
:
598 enc
= wxFONTENCODING_MACCENTRALEUR
;
600 case kTextEncodingMacVietnamese
:
601 enc
= wxFONTENCODING_MACVIATNAMESE
;
603 case kTextEncodingMacExtArabic
:
604 enc
= wxFONTENCODING_MACARABICEXT
;
606 case kTextEncodingMacSymbol
:
607 enc
= wxFONTENCODING_MACSYMBOL
;
609 case kTextEncodingMacDingbats
:
610 enc
= wxFONTENCODING_MACDINGBATS
;
612 case kTextEncodingMacTurkish
:
613 enc
= wxFONTENCODING_MACTURKISH
;
615 case kTextEncodingMacCroatian
:
616 enc
= wxFONTENCODING_MACCROATIAN
;
618 case kTextEncodingMacIcelandic
:
619 enc
= wxFONTENCODING_MACICELANDIC
;
621 case kTextEncodingMacRomanian
:
622 enc
= wxFONTENCODING_MACROMANIAN
;
624 case kTextEncodingMacCeltic
:
625 enc
= wxFONTENCODING_MACCELTIC
;
627 case kTextEncodingMacGaelic
:
628 enc
= wxFONTENCODING_MACGAELIC
;
630 case kTextEncodingMacKeyboardGlyphs
:
631 enc
= wxFONTENCODING_MACKEYBOARD
;