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
,
39 wxFAIL_MSG( "enumerating only fixed width fonts not supported" );
44 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
47 ATSFontFamilyIterator theFontFamilyIterator
= NULL
;
48 ATSFontFamilyRef theATSFontFamilyRef
= 0;
49 OSStatus status
= noErr
;
51 wxArrayString fontFamilies
;
53 // Create the iterator
54 status
= ATSFontFamilyIteratorCreate(kATSFontContextLocal
, nil
,nil
,
55 kATSOptionFlagsUnRestrictedScope
,
56 &theFontFamilyIterator
);
58 wxUint32 macEncoding
= wxMacGetSystemEncFromFontEnc(encoding
) ;
60 while (status
== noErr
)
62 // Get the next font in the iteration.
63 status
= ATSFontFamilyIteratorNext( theFontFamilyIterator
, &theATSFontFamilyRef
);
67 // TODO CS : Find replacement
68 // added CS : avoid showing fonts that won't be displayable
69 FMFontStyle intrinsicStyle
= 0 ;
71 FMFontFamily fmFamily
= FMGetFontFamilyFromATSFontFamilyRef( theATSFontFamilyRef
);
72 status
= FMGetFontFromFontFamilyInstance( fmFamily
, 0 , &fontInstance
, &intrinsicStyle
);
73 if ( status
!= noErr
)
79 if ( encoding
!= wxFONTENCODING_SYSTEM
)
81 TextEncoding fontFamiliyEncoding
= ATSFontFamilyGetEncoding(theATSFontFamilyRef
) ;
82 if ( fontFamiliyEncoding
!= macEncoding
)
86 // TODO: determine fixed widths ...
88 CFStringRef theName
= NULL
;
89 ATSFontFamilyGetName(theATSFontFamilyRef
, kATSOptionFlagsDefault
, &theName
);
90 wxCFStringRef
cfName(theName
) ;
91 fontFamilies
.Add(cfName
.AsString(wxLocale::GetSystemEncoding()));
93 else if (status
== kATSIterationScopeModified
) // Make sure the font database hasnÕt changed.
96 status
= ATSFontFamilyIteratorReset (kATSFontContextLocal
, nil
, nil
,
97 kATSOptionFlagsUnRestrictedScope
,
98 &theFontFamilyIterator
);
99 fontFamilies
.Clear() ;
102 ATSFontFamilyIteratorRelease(&theFontFamilyIterator
);
104 for ( size_t i
= 0 ; i
< fontFamilies
.Count() ; ++i
)
106 if ( OnFacename( fontFamilies
[i
] ) == false )
113 bool wxFontEnumerator::EnumerateEncodings(const wxString
& WXUNUSED(family
))
115 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
120 #endif // wxUSE_FONTENUM