]> git.saurik.com Git - wxWidgets.git/blob - src/osx/core/fontenum.cpp
changing to allow for 2x ramping up NSApp run
[wxWidgets.git] / src / osx / core / fontenum.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/core/fontenum.cpp
3 // Purpose: wxFontEnumerator class for MacOS
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #if wxUSE_FONTENUM
15
16 #include "wx/fontenum.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/font.h"
20 #include "wx/intl.h"
21 #endif
22
23 #include "wx/fontutil.h"
24 #include "wx/fontmap.h"
25 #include "wx/encinfo.h"
26
27 #include "wx/osx/private.h"
28
29 // ----------------------------------------------------------------------------
30 // wxFontEnumerator
31 // ----------------------------------------------------------------------------
32
33 #if wxOSX_USE_IPHONE
34 extern CFArrayRef CopyAvailableFontFamilyNames();
35 #endif
36
37 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
38 bool fixedWidthOnly)
39 {
40 wxArrayString fontFamilies ;
41
42 wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ;
43
44 #if wxOSX_USE_CORE_TEXT
45 {
46 CFArrayRef cfFontFamilies = nil;
47
48 #if wxOSX_USE_COCOA_OR_CARBON
49 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
50 if ( UMAGetSystemVersion() >= 0x1060 )
51 cfFontFamilies = CTFontManagerCopyAvailableFontFamilyNames();
52 else
53 #endif
54 {
55 #if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
56 //
57 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
58 //
59
60 CFMutableArrayRef atsfontnames = CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks);;
61
62 ATSFontFamilyIterator theFontFamilyIterator = NULL;
63 ATSFontFamilyRef theATSFontFamilyRef = 0;
64 OSStatus status = noErr;
65
66 // Create the iterator
67 status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil,
68 kATSOptionFlagsUnRestrictedScope,
69 &theFontFamilyIterator );
70
71 while (status == noErr)
72 {
73 // Get the next font in the iteration.
74 status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef );
75 if(status == noErr)
76 {
77 CFStringRef theName = NULL;
78 ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
79 CFArrayAppendValue(atsfontnames, theName);
80 CFRelease(theName);
81
82 }
83 else if (status == kATSIterationScopeModified) // Make sure the font database hasn't changed.
84 {
85 // reset the iterator
86 status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
87 kATSOptionFlagsUnRestrictedScope,
88 &theFontFamilyIterator);
89 CFArrayRemoveAllValues(atsfontnames);
90 }
91 }
92 ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
93 cfFontFamilies = atsfontnames;
94 #endif
95 }
96 #elif wxOSX_USE_IPHONE
97 cfFontFamilies = CopyAvailableFontFamilyNames();
98 #endif
99
100 CFIndex count = CFArrayGetCount(cfFontFamilies);
101 for(CFIndex i = 0; i < count; i++)
102 {
103 CFStringRef fontName = (CFStringRef)CFArrayGetValueAtIndex(cfFontFamilies, i);
104
105 if ( encoding != wxFONTENCODING_SYSTEM || fixedWidthOnly)
106 {
107 wxCFRef<CTFontRef> font(CTFontCreateWithName(fontName, 12.0, NULL));
108 if ( encoding != wxFONTENCODING_SYSTEM )
109 {
110 CFStringEncoding fontFamiliyEncoding = CTFontGetStringEncoding(font);
111 if ( fontFamiliyEncoding != macEncoding )
112 continue;
113 }
114
115 if ( fixedWidthOnly )
116 {
117 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font);
118 if ( (traits & kCTFontMonoSpaceTrait) == 0 )
119 continue;
120 }
121
122 }
123
124 wxCFStringRef cfName(wxCFRetain(fontName)) ;
125 fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding()));
126 }
127
128 CFRelease(cfFontFamilies);
129 }
130 #endif
131 for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
132 {
133 if ( OnFacename( fontFamilies[i] ) == false )
134 break ;
135 }
136
137 return true;
138 }
139
140 bool wxFontEnumerator::EnumerateEncodings(const wxString& WXUNUSED(family))
141 {
142 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
143
144 return true;
145 }
146
147 #endif // wxUSE_FONTENUM