]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/fontenum.cpp
only available on carbon or cocoa
[wxWidgets.git] / src / mac / carbon / fontenum.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/fontenum.cpp
3 // Purpose: wxFontEnumerator class for MacOS
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #if wxUSE_FONTENUM
16
17 #include "wx/fontenum.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/font.h"
21 #include "wx/intl.h"
22 #endif
23
24 #include "wx/fontutil.h"
25 #include "wx/fontmap.h"
26 #include "wx/encinfo.h"
27
28 #include "wx/mac/private.h"
29
30 // ----------------------------------------------------------------------------
31 // wxFontEnumerator
32 // ----------------------------------------------------------------------------
33
34 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
35 bool fixedWidthOnly)
36 {
37 if ( fixedWidthOnly )
38 {
39 wxFAIL_MSG( "enumerating only fixed width fonts not supported" );
40 return false;
41 }
42
43 wxArrayString fontFamilies ;
44
45 #if wxMAC_USE_ATSU_TEXT || wxMAC_USE_CORE_TEXT
46
47 //
48 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
49 //
50
51 ATSFontFamilyIterator theFontFamilyIterator = NULL;
52 ATSFontFamilyRef theATSFontFamilyRef = 0;
53 OSStatus status = noErr;
54
55 // Create the iterator
56 status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil,
57 kATSOptionFlagsUnRestrictedScope,
58 &theFontFamilyIterator );
59
60 wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ;
61
62 while (status == noErr)
63 {
64 // Get the next font in the iteration.
65 status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef );
66 if(status == noErr)
67 {
68 #ifndef __LP64__
69 // TODO CS : Find replacement
70 // added CS : avoid showing fonts that won't be displayable
71 FMFontStyle intrinsicStyle = 0 ;
72 FMFont fontInstance ;
73 FMFontFamily fmFamily = FMGetFontFamilyFromATSFontFamilyRef( theATSFontFamilyRef );
74 status = FMGetFontFromFontFamilyInstance( fmFamily , 0 , &fontInstance , &intrinsicStyle);
75 if ( status != noErr )
76 {
77 status = noErr;
78 continue ;
79 }
80 #endif
81 if ( encoding != wxFONTENCODING_SYSTEM )
82 {
83 TextEncoding fontFamiliyEncoding = ATSFontFamilyGetEncoding(theATSFontFamilyRef) ;
84 if ( fontFamiliyEncoding != macEncoding )
85 continue ;
86 }
87
88 // TODO: determine fixed widths ...
89
90 CFStringRef theName = NULL;
91 ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
92 wxCFStringRef cfName(theName) ;
93 fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding()));
94 }
95 else if (status == kATSIterationScopeModified) // Make sure the font database hasnÕt changed.
96 {
97 // reset the iterator
98 status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
99 kATSOptionFlagsUnRestrictedScope,
100 &theFontFamilyIterator);
101 fontFamilies.Clear() ;
102 }
103 }
104 ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
105 #endif
106
107 for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
108 {
109 if ( OnFacename( fontFamilies[i] ) == false )
110 break ;
111 }
112
113 return true;
114 }
115
116 bool wxFontEnumerator::EnumerateEncodings(const wxString& WXUNUSED(family))
117 {
118 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
119
120 return true;
121 }
122
123 #endif // wxUSE_FONTENUM