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
);
61 // TODO CS : Find replacement
62 // added CS : avoid showing fonts that won't be displayable
63 FMFontStyle intrinsicStyle
= 0 ;
65 FMFontFamily fmFamily
= FMGetFontFamilyFromATSFontFamilyRef( theATSFontFamilyRef
);
66 status
= FMGetFontFromFontFamilyInstance( fmFamily
, 0 , &fontInstance
, &intrinsicStyle
);
67 if ( status
!= noErr
)
73 if ( encoding
!= wxFONTENCODING_SYSTEM
)
75 TextEncoding fontFamiliyEncoding
= ATSFontFamilyGetEncoding(theATSFontFamilyRef
) ;
76 if ( fontFamiliyEncoding
!= macEncoding
)
80 // TODO: determine fixed widths ...
82 CFStringRef theName
= NULL
;
83 ATSFontFamilyGetName(theATSFontFamilyRef
, kATSOptionFlagsDefault
, &theName
);
84 wxMacCFStringHolder
cfName(theName
) ;
85 fontFamilies
.Add(cfName
.AsString(wxLocale::GetSystemEncoding()));
87 else if (status
== kATSIterationScopeModified
) // Make sure the font database hasnÕt changed.
90 status
= ATSFontFamilyIteratorReset (kATSFontContextLocal
, nil
, nil
,
91 kATSOptionFlagsUnRestrictedScope
,
92 &theFontFamilyIterator
);
93 fontFamilies
.Clear() ;
96 ATSFontFamilyIteratorRelease(&theFontFamilyIterator
);
98 for ( size_t i
= 0 ; i
< fontFamilies
.Count() ; ++i
)
100 if ( OnFacename( fontFamilies
[i
] ) == false )
107 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
109 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
114 #endif // wxUSE_FONTENUM