1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/core/fontenum.cpp
3 // Purpose: wxFontEnumerator class for MacOS
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
16 #include "wx/fontenum.h"
23 #include "wx/fontutil.h"
24 #include "wx/fontmap.h"
25 #include "wx/encinfo.h"
27 #include "wx/osx/private.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
34 extern CFArrayRef
CopyAvailableFontFamilyNames();
37 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
40 wxArrayString fontFamilies
;
42 wxUint32 macEncoding
= wxMacGetSystemEncFromFontEnc(encoding
) ;
44 #if wxOSX_USE_CORE_TEXT
46 CFArrayRef cfFontFamilies
= nil
;
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();
55 #if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
57 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
60 CFMutableArrayRef atsfontnames
= CFArrayCreateMutable(kCFAllocatorDefault
,0,&kCFTypeArrayCallBacks
);;
62 ATSFontFamilyIterator theFontFamilyIterator
= NULL
;
63 ATSFontFamilyRef theATSFontFamilyRef
= 0;
64 OSStatus status
= noErr
;
66 // Create the iterator
67 status
= ATSFontFamilyIteratorCreate(kATSFontContextLocal
, nil
,nil
,
68 kATSOptionFlagsUnRestrictedScope
,
69 &theFontFamilyIterator
);
71 while (status
== noErr
)
73 // Get the next font in the iteration.
74 status
= ATSFontFamilyIteratorNext( theFontFamilyIterator
, &theATSFontFamilyRef
);
77 CFStringRef theName
= NULL
;
78 ATSFontFamilyGetName(theATSFontFamilyRef
, kATSOptionFlagsDefault
, &theName
);
79 CFArrayAppendValue(atsfontnames
, theName
);
83 else if (status
== kATSIterationScopeModified
) // Make sure the font database hasn't changed.
86 status
= ATSFontFamilyIteratorReset (kATSFontContextLocal
, nil
, nil
,
87 kATSOptionFlagsUnRestrictedScope
,
88 &theFontFamilyIterator
);
89 CFArrayRemoveAllValues(atsfontnames
);
92 ATSFontFamilyIteratorRelease(&theFontFamilyIterator
);
93 cfFontFamilies
= atsfontnames
;
96 #elif wxOSX_USE_IPHONE
97 cfFontFamilies
= CopyAvailableFontFamilyNames();
100 CFIndex count
= CFArrayGetCount(cfFontFamilies
);
101 for(CFIndex i
= 0; i
< count
; i
++)
103 CFStringRef fontName
= (CFStringRef
)CFArrayGetValueAtIndex(cfFontFamilies
, i
);
105 if ( encoding
!= wxFONTENCODING_SYSTEM
|| fixedWidthOnly
)
107 wxCFRef
<CTFontRef
> font(CTFontCreateWithName(fontName
, 12.0, NULL
));
108 if ( encoding
!= wxFONTENCODING_SYSTEM
)
110 CFStringEncoding fontFamiliyEncoding
= CTFontGetStringEncoding(font
);
111 if ( fontFamiliyEncoding
!= macEncoding
)
115 if ( fixedWidthOnly
)
117 CTFontSymbolicTraits traits
= CTFontGetSymbolicTraits(font
);
118 if ( (traits
& kCTFontMonoSpaceTrait
) == 0 )
124 wxCFStringRef
cfName(wxCFRetain(fontName
)) ;
125 fontFamilies
.Add(cfName
.AsString(wxLocale::GetSystemEncoding()));
128 CFRelease(cfFontFamilies
);
131 for ( size_t i
= 0 ; i
< fontFamilies
.Count() ; ++i
)
133 if ( OnFacename( fontFamilies
[i
] ) == false )
140 bool wxFontEnumerator::EnumerateEncodings(const wxString
& WXUNUSED(family
))
142 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
147 #endif // wxUSE_FONTENUM