1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/core/fontenum.cpp
3 // Purpose: wxFontEnumerator class for MacOS
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
17 #include "wx/fontenum.h"
24 #include "wx/fontutil.h"
25 #include "wx/fontmap.h"
26 #include "wx/encinfo.h"
28 #include "wx/osx/private.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
35 extern CFArrayRef
CopyAvailableFontFamilyNames();
38 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
41 wxArrayString fontFamilies
;
43 wxUint32 macEncoding
= wxMacGetSystemEncFromFontEnc(encoding
) ;
45 #if wxOSX_USE_CORE_TEXT
47 CFArrayRef cfFontFamilies
= nil
;
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();
56 #if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
58 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
61 CFMutableArrayRef atsfontnames
= CFArrayCreateMutable(kCFAllocatorDefault
,0,&kCFTypeArrayCallBacks
);;
63 ATSFontFamilyIterator theFontFamilyIterator
= NULL
;
64 ATSFontFamilyRef theATSFontFamilyRef
= 0;
65 OSStatus status
= noErr
;
67 // Create the iterator
68 status
= ATSFontFamilyIteratorCreate(kATSFontContextLocal
, nil
,nil
,
69 kATSOptionFlagsUnRestrictedScope
,
70 &theFontFamilyIterator
);
72 while (status
== noErr
)
74 // Get the next font in the iteration.
75 status
= ATSFontFamilyIteratorNext( theFontFamilyIterator
, &theATSFontFamilyRef
);
78 CFStringRef theName
= NULL
;
79 ATSFontFamilyGetName(theATSFontFamilyRef
, kATSOptionFlagsDefault
, &theName
);
80 CFArrayAppendValue(atsfontnames
, theName
);
84 else if (status
== kATSIterationScopeModified
) // Make sure the font database hasn't changed.
87 status
= ATSFontFamilyIteratorReset (kATSFontContextLocal
, nil
, nil
,
88 kATSOptionFlagsUnRestrictedScope
,
89 &theFontFamilyIterator
);
90 CFArrayRemoveAllValues(atsfontnames
);
93 ATSFontFamilyIteratorRelease(&theFontFamilyIterator
);
94 cfFontFamilies
= atsfontnames
;
97 #elif wxOSX_USE_IPHONE
98 cfFontFamilies
= CopyAvailableFontFamilyNames();
101 CFIndex count
= CFArrayGetCount(cfFontFamilies
);
102 for(CFIndex i
= 0; i
< count
; i
++)
104 CFStringRef fontName
= (CFStringRef
)CFArrayGetValueAtIndex(cfFontFamilies
, i
);
106 if ( encoding
!= wxFONTENCODING_SYSTEM
|| fixedWidthOnly
)
108 wxCFRef
<CTFontRef
> font(CTFontCreateWithName(fontName
, 12.0, NULL
));
109 if ( encoding
!= wxFONTENCODING_SYSTEM
)
111 CFStringEncoding fontFamiliyEncoding
= CTFontGetStringEncoding(font
);
112 if ( fontFamiliyEncoding
!= macEncoding
)
116 if ( fixedWidthOnly
)
118 CTFontSymbolicTraits traits
= CTFontGetSymbolicTraits(font
);
119 if ( (traits
& kCTFontMonoSpaceTrait
) == 0 )
125 wxCFStringRef
cfName(wxCFRetain(fontName
)) ;
126 fontFamilies
.Add(cfName
.AsString(wxLocale::GetSystemEncoding()));
129 CFRelease(cfFontFamilies
);
132 for ( size_t i
= 0 ; i
< fontFamilies
.Count() ; ++i
)
134 if ( OnFacename( fontFamilies
[i
] ) == false )
141 bool wxFontEnumerator::EnumerateEncodings(const wxString
& WXUNUSED(family
))
143 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
148 #endif // wxUSE_FONTENUM