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 // ----------------------------------------------------------------------------
34 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
37 wxArrayString fontFamilies
;
39 wxUint32 macEncoding
= wxMacGetSystemEncFromFontEnc(encoding
) ;
41 #if wxOSX_USE_CORE_TEXT
43 CFArrayRef cfFontFamilies
= nil
;
45 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
46 if ( UMAGetSystemVersion() >= 0x1060 )
47 cfFontFamilies
= CTFontManagerCopyAvailableFontFamilyNames();
51 #if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6) && wxOSX_USE_ATSU_TEXT
53 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
56 CFMutableArrayRef atsfontnames
= CFArrayCreateMutable(kCFAllocatorDefault
,0,&kCFTypeArrayCallBacks
);;
58 ATSFontFamilyIterator theFontFamilyIterator
= NULL
;
59 ATSFontFamilyRef theATSFontFamilyRef
= 0;
60 OSStatus status
= noErr
;
62 // Create the iterator
63 status
= ATSFontFamilyIteratorCreate(kATSFontContextLocal
, nil
,nil
,
64 kATSOptionFlagsUnRestrictedScope
,
65 &theFontFamilyIterator
);
67 while (status
== noErr
)
69 // Get the next font in the iteration.
70 status
= ATSFontFamilyIteratorNext( theFontFamilyIterator
, &theATSFontFamilyRef
);
73 CFStringRef theName
= NULL
;
74 ATSFontFamilyGetName(theATSFontFamilyRef
, kATSOptionFlagsDefault
, &theName
);
75 CFArrayAppendValue(atsfontnames
, theName
);
79 else if (status
== kATSIterationScopeModified
) // Make sure the font database hasn't changed.
82 status
= ATSFontFamilyIteratorReset (kATSFontContextLocal
, nil
, nil
,
83 kATSOptionFlagsUnRestrictedScope
,
84 &theFontFamilyIterator
);
85 CFArrayRemoveAllValues(atsfontnames
);
88 ATSFontFamilyIteratorRelease(&theFontFamilyIterator
);
89 cfFontFamilies
= atsfontnames
;
93 CFIndex count
= CFArrayGetCount(cfFontFamilies
);
94 for(CFIndex i
= 0; i
< count
; i
++)
96 CFStringRef fontName
= (CFStringRef
)CFArrayGetValueAtIndex(cfFontFamilies
, i
);
98 if ( encoding
!= wxFONTENCODING_SYSTEM
|| fixedWidthOnly
)
100 wxCFRef
<CTFontRef
> font(CTFontCreateWithName(fontName
, 12.0, NULL
));
101 if ( encoding
!= wxFONTENCODING_SYSTEM
)
103 CFStringEncoding fontFamiliyEncoding
= CTFontGetStringEncoding(font
);
104 if ( fontFamiliyEncoding
!= macEncoding
)
108 if ( fixedWidthOnly
)
110 CTFontSymbolicTraits traits
= CTFontGetSymbolicTraits(font
);
111 if ( (traits
& kCTFontMonoSpaceTrait
) == 0 )
117 wxCFStringRef
cfName(wxCFRetain(fontName
)) ;
118 fontFamilies
.Add(cfName
.AsString(wxLocale::GetSystemEncoding()));
121 CFRelease(cfFontFamilies
);
124 for ( size_t i
= 0 ; i
< fontFamilies
.Count() ; ++i
)
126 if ( OnFacename( fontFamilies
[i
] ) == false )
133 bool wxFontEnumerator::EnumerateEncodings(const wxString
& WXUNUSED(family
))
135 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
140 #endif // wxUSE_FONTENUM