]> git.saurik.com Git - wxWidgets.git/blob - src/osx/core/fontenum.cpp
as we always have CoreText available under 10.5+, we can properly determine fixed...
[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 // 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/osx/private.h"
29
30 // ----------------------------------------------------------------------------
31 // wxFontEnumerator
32 // ----------------------------------------------------------------------------
33
34 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
35 bool fixedWidthOnly)
36 {
37 wxArrayString fontFamilies ;
38
39 wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ;
40
41 #if wxOSX_USE_CORE_TEXT
42 {
43 CFArrayRef cfFontFamilies = nil;
44
45 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
46 if ( UMAGetSystemVersion() >= 0x1060 )
47 cfFontFamilies = CTFontManagerCopyAvailableFontFamilyNames();
48 else
49 #endif
50 {
51 #if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6) && wxOSX_USE_ATSU_TEXT
52 //
53 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
54 //
55
56 CFMutableArrayRef atsfontnames = CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks);;
57
58 ATSFontFamilyIterator theFontFamilyIterator = NULL;
59 ATSFontFamilyRef theATSFontFamilyRef = 0;
60 OSStatus status = noErr;
61
62 // Create the iterator
63 status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil,
64 kATSOptionFlagsUnRestrictedScope,
65 &theFontFamilyIterator );
66
67 while (status == noErr)
68 {
69 // Get the next font in the iteration.
70 status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef );
71 if(status == noErr)
72 {
73 CFStringRef theName = NULL;
74 ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
75 CFArrayAppendValue(atsfontnames, theName);
76 CFRelease(theName);
77
78 }
79 else if (status == kATSIterationScopeModified) // Make sure the font database hasn't changed.
80 {
81 // reset the iterator
82 status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
83 kATSOptionFlagsUnRestrictedScope,
84 &theFontFamilyIterator);
85 CFArrayRemoveAllValues(atsfontnames);
86 }
87 }
88 ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
89 cfFontFamilies = atsfontnames;
90 #endif
91 }
92
93 CFIndex count = CFArrayGetCount(cfFontFamilies);
94 for(CFIndex i = 0; i < count; i++)
95 {
96 CFStringRef fontName = (CFStringRef)CFArrayGetValueAtIndex(cfFontFamilies, i);
97
98 if ( encoding != wxFONTENCODING_SYSTEM || fixedWidthOnly)
99 {
100 wxCFRef<CTFontRef> font(CTFontCreateWithName(fontName, 12.0, NULL));
101 if ( encoding != wxFONTENCODING_SYSTEM )
102 {
103 CFStringEncoding fontFamiliyEncoding = CTFontGetStringEncoding(font);
104 if ( fontFamiliyEncoding != macEncoding )
105 continue;
106 }
107
108 if ( fixedWidthOnly )
109 {
110 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font);
111 if ( (traits & kCTFontMonoSpaceTrait) == 0 )
112 continue;
113 }
114
115 }
116
117 wxCFStringRef cfName(wxCFRetain(fontName)) ;
118 fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding()));
119 }
120
121 CFRelease(cfFontFamilies);
122 }
123 #endif
124 for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
125 {
126 if ( OnFacename( fontFamilies[i] ) == false )
127 break ;
128 }
129
130 return true;
131 }
132
133 bool wxFontEnumerator::EnumerateEncodings(const wxString& WXUNUSED(family))
134 {
135 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
136
137 return true;
138 }
139
140 #endif // wxUSE_FONTENUM