]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/fontutil.cpp
Fixed DDE memory leaks.
[wxWidgets.git] / src / mac / carbon / fontutil.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/fontutil.cpp
3 // Purpose: font-related helper functions for wxMSW
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 05.11.99
7 // RCS-ID: $Id$
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "fontutil.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/string.h"
33 #include "wx/log.h"
34 #include "wx/intl.h"
35 #endif //WX_PRECOMP
36
37 #include "wx/fontutil.h"
38 #include "wx/fontmap.h"
39 #include "wx/encinfo.h"
40
41 #include "wx/tokenzr.h"
42
43 #include "ATSUnicode.h"
44 #include "TextCommon.h"
45 #include "TextEncodingConverter.h"
46
47 #include "wx/mac/private.h" // includes mac headers
48
49 // ============================================================================
50 // implementation
51 // ============================================================================
52
53 // ----------------------------------------------------------------------------
54 // wxNativeEncodingInfo
55 // ----------------------------------------------------------------------------
56
57 // convert to/from the string representation: format is
58 // facename[;charset]
59
60 bool wxNativeEncodingInfo::FromString(const wxString& s)
61 {
62 wxStringTokenizer tokenizer(s, _T(";"));
63
64 facename = tokenizer.GetNextToken();
65 if ( !facename )
66 return FALSE;
67
68 wxString tmp = tokenizer.GetNextToken();
69 if ( !tmp )
70 {
71 // default charset (don't use DEFAULT_CHARSET though because of subtle
72 // Windows 9x/NT differences in handling it)
73 charset = 0;
74 }
75 else
76 {
77 if ( wxSscanf(tmp, _T("%u"), &charset) != 1 )
78 {
79 // should be a number!
80 return FALSE;
81 }
82 }
83
84 return TRUE;
85 }
86
87 wxString wxNativeEncodingInfo::ToString() const
88 {
89 wxString s(facename);
90 if ( charset != 0 )
91 {
92 s << _T(';') << charset;
93 }
94
95 return s;
96 }
97
98 // ----------------------------------------------------------------------------
99 // helper functions
100 // ----------------------------------------------------------------------------
101
102 bool wxGetNativeFontEncoding(wxFontEncoding encoding,
103 wxNativeEncodingInfo *info)
104 {
105 wxCHECK_MSG( info, FALSE, _T("bad pointer in wxGetNativeFontEncoding") );
106
107 if ( encoding == wxFONTENCODING_DEFAULT )
108 {
109 encoding = wxFont::GetDefaultEncoding();
110 }
111
112 info->encoding = encoding ;
113
114 return TRUE;
115 }
116
117 bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
118 {
119 return info.encoding == wxFont::GetDefaultEncoding() ;
120 }
121
122 wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
123 {
124 TextEncodingBase enc = 0 ;
125
126 switch( encoding)
127 {
128 case wxFONTENCODING_ISO8859_1 :
129 enc = kTextEncodingISOLatin1 ;
130 break ;
131 case wxFONTENCODING_ISO8859_2 :
132 enc = kTextEncodingISOLatin2;
133 break ;
134 case wxFONTENCODING_ISO8859_3 :
135 enc = kTextEncodingISOLatin3 ;
136 break ;
137 case wxFONTENCODING_ISO8859_4 :
138 enc = kTextEncodingISOLatin4;
139 break ;
140 case wxFONTENCODING_ISO8859_5 :
141 enc = kTextEncodingISOLatinCyrillic;
142 break ;
143 case wxFONTENCODING_ISO8859_6 :
144 enc = kTextEncodingISOLatinArabic;
145 break ;
146 case wxFONTENCODING_ISO8859_7 :
147 enc = kTextEncodingISOLatinGreek;
148 break ;
149 case wxFONTENCODING_ISO8859_8 :
150 enc = kTextEncodingISOLatinHebrew;
151 break ;
152 case wxFONTENCODING_ISO8859_9 :
153 enc = kTextEncodingISOLatin5;
154 break ;
155 case wxFONTENCODING_ISO8859_10 :
156 enc = kTextEncodingISOLatin6;
157 break ;
158 case wxFONTENCODING_ISO8859_13 :
159 enc = kTextEncodingISOLatin7;
160 break ;
161 case wxFONTENCODING_ISO8859_14 :
162 enc = kTextEncodingISOLatin8;
163 break ;
164 case wxFONTENCODING_ISO8859_15 :
165 enc = kTextEncodingISOLatin9;
166 break ;
167
168 case wxFONTENCODING_KOI8 :
169 enc = kTextEncodingKOI8_R;
170 break ;
171 case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866
172 enc = kTextEncodingDOSRussian;
173 break ;
174 /*
175 case wxFONTENCODING_BULGARIAN :
176 enc = ;
177 break ;
178 */
179 case wxFONTENCODING_CP437 :
180 enc =kTextEncodingDOSLatinUS ;
181 break ;
182 case wxFONTENCODING_CP850 :
183 enc = kTextEncodingDOSLatin1;
184 break ;
185 case wxFONTENCODING_CP852 :
186 enc = kTextEncodingDOSLatin2;
187 break ;
188 case wxFONTENCODING_CP855 :
189 enc = kTextEncodingDOSCyrillic;
190 break ;
191 case wxFONTENCODING_CP866 :
192 enc =kTextEncodingDOSRussian ;
193 break ;
194 case wxFONTENCODING_CP874 :
195 enc = kTextEncodingDOSThai;
196 break ;
197 case wxFONTENCODING_CP932 :
198 enc = kTextEncodingDOSJapanese;
199 break ;
200 case wxFONTENCODING_CP936 :
201 enc =kTextEncodingDOSChineseSimplif ;
202 break ;
203 case wxFONTENCODING_CP949 :
204 enc = kTextEncodingDOSKorean;
205 break ;
206 case wxFONTENCODING_CP950 :
207 enc = kTextEncodingDOSChineseTrad;
208 break ;
209
210 case wxFONTENCODING_CP1250 :
211 enc = kTextEncodingWindowsLatin2;
212 break ;
213 case wxFONTENCODING_CP1251 :
214 enc =kTextEncodingWindowsCyrillic ;
215 break ;
216 case wxFONTENCODING_CP1252 :
217 enc =kTextEncodingWindowsLatin1 ;
218 break ;
219 case wxFONTENCODING_CP1253 :
220 enc = kTextEncodingWindowsGreek;
221 break ;
222 case wxFONTENCODING_CP1254 :
223 enc = kTextEncodingWindowsLatin5;
224 break ;
225 case wxFONTENCODING_CP1255 :
226 enc =kTextEncodingWindowsHebrew ;
227 break ;
228 case wxFONTENCODING_CP1256 :
229 enc =kTextEncodingWindowsArabic ;
230 break ;
231 case wxFONTENCODING_CP1257 :
232 enc = kTextEncodingWindowsBalticRim;
233 break ;
234
235 case wxFONTENCODING_UTF7 :
236 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
237 break ;
238 case wxFONTENCODING_UTF8 :
239 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
240 break ;
241 case wxFONTENCODING_EUC_JP :
242 enc = kTextEncodingEUC_JP;
243 break ;
244 case wxFONTENCODING_UTF16BE :
245 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
246 break ;
247 case wxFONTENCODING_UTF16LE :
248 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
249 break ;
250 case wxFONTENCODING_UTF32BE :
251 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
252 break ;
253 case wxFONTENCODING_UTF32LE :
254 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
255 break ;
256
257 case wxFONTENCODING_MACROMAN :
258 enc = kTextEncodingMacRoman ;
259 break ;
260 case wxFONTENCODING_MACJAPANESE :
261 enc = kTextEncodingMacJapanese ;
262 break ;
263 case wxFONTENCODING_MACCHINESETRAD :
264 enc = kTextEncodingMacChineseTrad ;
265 break ;
266 case wxFONTENCODING_MACKOREAN :
267 enc = kTextEncodingMacKorean ;
268 break ;
269 case wxFONTENCODING_MACARABIC :
270 enc = kTextEncodingMacArabic ;
271 break ;
272 case wxFONTENCODING_MACHEBREW :
273 enc = kTextEncodingMacHebrew ;
274 break ;
275 case wxFONTENCODING_MACGREEK :
276 enc = kTextEncodingMacGreek ;
277 break ;
278 case wxFONTENCODING_MACCYRILLIC :
279 enc = kTextEncodingMacCyrillic ;
280 break ;
281 case wxFONTENCODING_MACDEVANAGARI :
282 enc = kTextEncodingMacDevanagari ;
283 break ;
284 case wxFONTENCODING_MACGURMUKHI :
285 enc = kTextEncodingMacGurmukhi ;
286 break ;
287 case wxFONTENCODING_MACGUJARATI :
288 enc = kTextEncodingMacGujarati ;
289 break ;
290 case wxFONTENCODING_MACORIYA :
291 enc = kTextEncodingMacOriya ;
292 break ;
293 case wxFONTENCODING_MACBENGALI :
294 enc = kTextEncodingMacBengali ;
295 break ;
296 case wxFONTENCODING_MACTAMIL :
297 enc = kTextEncodingMacTamil ;
298 break ;
299 case wxFONTENCODING_MACTELUGU :
300 enc = kTextEncodingMacTelugu ;
301 break ;
302 case wxFONTENCODING_MACKANNADA :
303 enc = kTextEncodingMacKannada ;
304 break ;
305 case wxFONTENCODING_MACMALAJALAM :
306 enc = kTextEncodingMacMalayalam ;
307 break ;
308 case wxFONTENCODING_MACSINHALESE :
309 enc = kTextEncodingMacSinhalese ;
310 break ;
311 case wxFONTENCODING_MACBURMESE :
312 enc = kTextEncodingMacBurmese ;
313 break ;
314 case wxFONTENCODING_MACKHMER :
315 enc = kTextEncodingMacKhmer ;
316 break ;
317 case wxFONTENCODING_MACTHAI :
318 enc = kTextEncodingMacThai ;
319 break ;
320 case wxFONTENCODING_MACLAOTIAN :
321 enc = kTextEncodingMacLaotian ;
322 break ;
323 case wxFONTENCODING_MACGEORGIAN :
324 enc = kTextEncodingMacGeorgian ;
325 break ;
326 case wxFONTENCODING_MACARMENIAN :
327 enc = kTextEncodingMacArmenian ;
328 break ;
329 case wxFONTENCODING_MACCHINESESIMP :
330 enc = kTextEncodingMacChineseSimp ;
331 break ;
332 case wxFONTENCODING_MACTIBETAN :
333 enc = kTextEncodingMacTibetan ;
334 break ;
335 case wxFONTENCODING_MACMONGOLIAN :
336 enc = kTextEncodingMacMongolian ;
337 break ;
338 case wxFONTENCODING_MACETHIOPIC :
339 enc = kTextEncodingMacEthiopic ;
340 break ;
341 case wxFONTENCODING_MACCENTRALEUR :
342 enc = kTextEncodingMacCentralEurRoman ;
343 break ;
344 case wxFONTENCODING_MACVIATNAMESE :
345 enc = kTextEncodingMacVietnamese ;
346 break ;
347 case wxFONTENCODING_MACARABICEXT :
348 enc = kTextEncodingMacExtArabic ;
349 break ;
350 case wxFONTENCODING_MACSYMBOL :
351 enc = kTextEncodingMacSymbol ;
352 break ;
353 case wxFONTENCODING_MACDINGBATS :
354 enc = kTextEncodingMacDingbats ;
355 break ;
356 case wxFONTENCODING_MACTURKISH :
357 enc = kTextEncodingMacTurkish ;
358 break ;
359 case wxFONTENCODING_MACCROATIAN :
360 enc = kTextEncodingMacCroatian ;
361 break ;
362 case wxFONTENCODING_MACICELANDIC :
363 enc = kTextEncodingMacIcelandic ;
364 break ;
365 case wxFONTENCODING_MACROMANIAN :
366 enc = kTextEncodingMacRomanian ;
367 break ;
368 case wxFONTENCODING_MACCELTIC :
369 enc = kTextEncodingMacCeltic ;
370 break ;
371 case wxFONTENCODING_MACGAELIC :
372 enc = kTextEncodingMacGaelic ;
373 break ;
374 case wxFONTENCODING_MACKEYBOARD :
375 enc = kTextEncodingMacKeyboardGlyphs ;
376 break ;
377 } ;
378 return enc ;
379 }
380
381 wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding)
382 {
383 wxFontEncoding enc = wxFONTENCODING_DEFAULT ;
384
385 switch( encoding)
386 {
387 case kTextEncodingISOLatin1 :
388 enc = wxFONTENCODING_ISO8859_1 ;
389 break ;
390 case kTextEncodingISOLatin2 :
391 enc = wxFONTENCODING_ISO8859_2;
392 break ;
393 case kTextEncodingISOLatin3 :
394 enc = wxFONTENCODING_ISO8859_3 ;
395 break ;
396 case kTextEncodingISOLatin4 :
397 enc = wxFONTENCODING_ISO8859_4;
398 break ;
399 case kTextEncodingISOLatinCyrillic :
400 enc = wxFONTENCODING_ISO8859_5;
401 break ;
402 case kTextEncodingISOLatinArabic :
403 enc = wxFONTENCODING_ISO8859_6;
404 break ;
405 case kTextEncodingISOLatinGreek :
406 enc = wxFONTENCODING_ISO8859_7;
407 break ;
408 case kTextEncodingISOLatinHebrew :
409 enc = wxFONTENCODING_ISO8859_8;
410 break ;
411 case kTextEncodingISOLatin5 :
412 enc = wxFONTENCODING_ISO8859_9;
413 break ;
414 case kTextEncodingISOLatin6 :
415 enc = wxFONTENCODING_ISO8859_10;
416 break ;
417 case kTextEncodingISOLatin7 :
418 enc = wxFONTENCODING_ISO8859_13;
419 break ;
420 case kTextEncodingISOLatin8 :
421 enc = wxFONTENCODING_ISO8859_14;
422 break ;
423 case kTextEncodingISOLatin9 :
424 enc =wxFONTENCODING_ISO8859_15 ;
425 break ;
426
427 case kTextEncodingKOI8_R :
428 enc = wxFONTENCODING_KOI8;
429 break ;
430 /*
431 case :
432 enc = wxFONTENCODING_BULGARIAN;
433 break ;
434 */
435 casekTextEncodingDOSLatinUS :
436 enc = wxFONTENCODING_CP437;
437 break ;
438 case kTextEncodingDOSLatin1 :
439 enc = wxFONTENCODING_CP850;
440 break ;
441 case kTextEncodingDOSLatin2 :
442 enc =wxFONTENCODING_CP852 ;
443 break ;
444 case kTextEncodingDOSCyrillic :
445 enc = wxFONTENCODING_CP855;
446 break ;
447 case kTextEncodingDOSRussian :
448 enc = wxFONTENCODING_CP866;
449 break ;
450 case kTextEncodingDOSThai :
451 enc =wxFONTENCODING_CP874 ;
452 break ;
453 case kTextEncodingDOSJapanese :
454 enc = wxFONTENCODING_CP932;
455 break ;
456 case kTextEncodingDOSChineseSimplif :
457 enc = wxFONTENCODING_CP936;
458 break ;
459 case kTextEncodingDOSKorean :
460 enc = wxFONTENCODING_CP949;
461 break ;
462 case kTextEncodingDOSChineseTrad :
463 enc = wxFONTENCODING_CP950;
464 break ;
465
466 case kTextEncodingWindowsLatin2 :
467 enc = wxFONTENCODING_CP1250;
468 break ;
469 case kTextEncodingWindowsCyrillic :
470 enc = wxFONTENCODING_CP1251;
471 break ;
472 case kTextEncodingWindowsLatin1 :
473 enc = wxFONTENCODING_CP1252;
474 break ;
475 case kTextEncodingWindowsGreek :
476 enc = wxFONTENCODING_CP1253;
477 break ;
478 case kTextEncodingWindowsLatin5 :
479 enc = wxFONTENCODING_CP1254;
480 break ;
481 case kTextEncodingWindowsHebrew :
482 enc = wxFONTENCODING_CP1255;
483 break ;
484 case kTextEncodingWindowsArabic :
485 enc = wxFONTENCODING_CP1256;
486 break ;
487 case kTextEncodingWindowsBalticRim :
488 enc =wxFONTENCODING_CP1257 ;
489 break ;
490 case kTextEncodingEUC_JP :
491 enc = wxFONTENCODING_EUC_JP;
492 break ;
493 /*
494 case wxFONTENCODING_UTF7 :
495 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
496 break ;
497 case wxFONTENCODING_UTF8 :
498 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
499 break ;
500 case wxFONTENCODING_UTF16BE :
501 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
502 break ;
503 case wxFONTENCODING_UTF16LE :
504 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
505 break ;
506 case wxFONTENCODING_UTF32BE :
507 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
508 break ;
509 case wxFONTENCODING_UTF32LE :
510 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
511 break ;
512 */
513 case kTextEncodingMacRoman :
514 enc = wxFONTENCODING_MACROMAN ;
515 break ;
516 case kTextEncodingMacJapanese :
517 enc = wxFONTENCODING_MACJAPANESE ;
518 break ;
519 case kTextEncodingMacChineseTrad :
520 enc = wxFONTENCODING_MACCHINESETRAD ;
521 break ;
522 case kTextEncodingMacKorean :
523 enc = wxFONTENCODING_MACKOREAN ;
524 break ;
525 case kTextEncodingMacArabic :
526 enc =wxFONTENCODING_MACARABIC ;
527 break ;
528 case kTextEncodingMacHebrew :
529 enc = wxFONTENCODING_MACHEBREW ;
530 break ;
531 case kTextEncodingMacGreek :
532 enc = wxFONTENCODING_MACGREEK ;
533 break ;
534 case kTextEncodingMacCyrillic :
535 enc = wxFONTENCODING_MACCYRILLIC ;
536 break ;
537 case kTextEncodingMacDevanagari :
538 enc = wxFONTENCODING_MACDEVANAGARI ;
539 break ;
540 case kTextEncodingMacGurmukhi :
541 enc = wxFONTENCODING_MACGURMUKHI ;
542 break ;
543 case kTextEncodingMacGujarati :
544 enc = wxFONTENCODING_MACGUJARATI ;
545 break ;
546 case kTextEncodingMacOriya :
547 enc =wxFONTENCODING_MACORIYA ;
548 break ;
549 case kTextEncodingMacBengali :
550 enc =wxFONTENCODING_MACBENGALI ;
551 break ;
552 case kTextEncodingMacTamil :
553 enc = wxFONTENCODING_MACTAMIL ;
554 break ;
555 case kTextEncodingMacTelugu :
556 enc = wxFONTENCODING_MACTELUGU ;
557 break ;
558 case kTextEncodingMacKannada :
559 enc = wxFONTENCODING_MACKANNADA ;
560 break ;
561 case kTextEncodingMacMalayalam :
562 enc = wxFONTENCODING_MACMALAJALAM ;
563 break ;
564 case kTextEncodingMacSinhalese :
565 enc = wxFONTENCODING_MACSINHALESE ;
566 break ;
567 case kTextEncodingMacBurmese :
568 enc = wxFONTENCODING_MACBURMESE ;
569 break ;
570 case kTextEncodingMacKhmer :
571 enc = wxFONTENCODING_MACKHMER ;
572 break ;
573 case kTextEncodingMacThai :
574 enc = wxFONTENCODING_MACTHAI ;
575 break ;
576 case kTextEncodingMacLaotian :
577 enc = wxFONTENCODING_MACLAOTIAN ;
578 break ;
579 case kTextEncodingMacGeorgian :
580 enc = wxFONTENCODING_MACGEORGIAN ;
581 break ;
582 case kTextEncodingMacArmenian :
583 enc = wxFONTENCODING_MACARMENIAN ;
584 break ;
585 case kTextEncodingMacChineseSimp :
586 enc = wxFONTENCODING_MACCHINESESIMP ;
587 break ;
588 case kTextEncodingMacTibetan :
589 enc = wxFONTENCODING_MACTIBETAN ;
590 break ;
591 case kTextEncodingMacMongolian :
592 enc = wxFONTENCODING_MACMONGOLIAN ;
593 break ;
594 case kTextEncodingMacEthiopic :
595 enc = wxFONTENCODING_MACETHIOPIC ;
596 break ;
597 case kTextEncodingMacCentralEurRoman:
598 enc = wxFONTENCODING_MACCENTRALEUR ;
599 break ;
600 case kTextEncodingMacVietnamese:
601 enc = wxFONTENCODING_MACVIATNAMESE ;
602 break ;
603 case kTextEncodingMacExtArabic :
604 enc = wxFONTENCODING_MACARABICEXT ;
605 break ;
606 case kTextEncodingMacSymbol :
607 enc = wxFONTENCODING_MACSYMBOL ;
608 break ;
609 case kTextEncodingMacDingbats :
610 enc = wxFONTENCODING_MACDINGBATS ;
611 break ;
612 case kTextEncodingMacTurkish :
613 enc = wxFONTENCODING_MACTURKISH ;
614 break ;
615 case kTextEncodingMacCroatian :
616 enc = wxFONTENCODING_MACCROATIAN ;
617 break ;
618 case kTextEncodingMacIcelandic :
619 enc = wxFONTENCODING_MACICELANDIC ;
620 break ;
621 case kTextEncodingMacRomanian :
622 enc = wxFONTENCODING_MACROMANIAN ;
623 break ;
624 case kTextEncodingMacCeltic :
625 enc = wxFONTENCODING_MACCELTIC ;
626 break ;
627 case kTextEncodingMacGaelic :
628 enc = wxFONTENCODING_MACGAELIC ;
629 break ;
630 case kTextEncodingMacKeyboardGlyphs :
631 enc = wxFONTENCODING_MACKEYBOARD ;
632 break ;
633 } ;
634 return enc ;
635 }
636