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