1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/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/mac/private.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
38 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
41 ATSFontFamilyIterator theFontFamilyIterator
= NULL
;
42 ATSFontFamilyRef theATSFontFamilyRef
= 0;
43 OSStatus status
= noErr
;
45 wxArrayString fontFamilies
;
47 // Create the iterator
48 status
= ATSFontFamilyIteratorCreate(kATSFontContextLocal
, nil
,nil
,
49 kATSOptionFlagsUnRestrictedScope
,
50 &theFontFamilyIterator
);
52 wxUint32 macEncoding
= wxMacGetSystemEncFromFontEnc(encoding
) ;
54 while (status
== noErr
)
56 // Get the next font in the iteration.
57 status
= ATSFontFamilyIteratorNext( theFontFamilyIterator
, &theATSFontFamilyRef
);
60 // added CS : avoid showing fonts that won't be displayable
61 FMFontStyle intrinsicStyle
= 0 ;
63 FMFontFamily fmFamily
= FMGetFontFamilyFromATSFontFamilyRef( theATSFontFamilyRef
);
64 status
= FMGetFontFromFontFamilyInstance( fmFamily
, 0 , &fontInstance
, &intrinsicStyle
);
65 if ( status
!= noErr
)
71 if ( encoding
!= wxFONTENCODING_SYSTEM
)
73 TextEncoding fontFamiliyEncoding
= ATSFontFamilyGetEncoding(theATSFontFamilyRef
) ;
74 if ( fontFamiliyEncoding
!= macEncoding
)
78 // TODO: determine fixed widths ...
80 CFStringRef theName
= NULL
;
81 ATSFontFamilyGetName(theATSFontFamilyRef
, kATSOptionFlagsDefault
, &theName
);
82 wxMacCFStringHolder
cfName(theName
) ;
83 fontFamilies
.Add(cfName
.AsString(wxLocale::GetSystemEncoding()));
85 else if (status
== kATSIterationScopeModified
) // Make sure the font database hasnÕt changed.
88 status
= ATSFontFamilyIteratorReset (kATSFontContextLocal
, nil
, nil
,
89 kATSOptionFlagsUnRestrictedScope
,
90 &theFontFamilyIterator
);
91 fontFamilies
.Clear() ;
94 ATSFontFamilyIteratorRelease(&theFontFamilyIterator
);
96 for ( size_t i
= 0 ; i
< fontFamilies
.Count() ; ++i
)
98 if ( OnFacename( fontFamilies
[i
] ) == false )
105 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
107 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
112 #endif // wxUSE_FONTMAP