]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/fontenum.cpp
3cbe7bad1bdb43a50d403f013973e6fb6bf26e75
[wxWidgets.git] / src / mac / carbon / fontenum.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/fontenum.cpp
3 // Purpose: wxFontEnumerator class for MacOS
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #if wxUSE_FONTMAP
16
17 #include "wx/fontenum.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/font.h"
21 #include "wx/intl.h"
22 #endif
23
24 #include "wx/fontutil.h"
25 #include "wx/fontmap.h"
26 #include "wx/encinfo.h"
27
28 #include "wx/mac/private.h"
29
30 // ----------------------------------------------------------------------------
31 // wxFontEnumerator
32 // ----------------------------------------------------------------------------
33
34 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
35 bool fixedWidthOnly)
36 {
37 //
38 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
39 //
40
41 ATSFontFamilyIterator theFontFamilyIterator = NULL;
42 ATSFontFamilyRef theATSFontFamilyRef = 0;
43 OSStatus status = noErr;
44
45 wxArrayString fontFamilies ;
46
47 // Create the iterator
48 status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil,
49 kATSOptionFlagsUnRestrictedScope,
50 &theFontFamilyIterator );
51
52 wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ;
53
54 while (status == noErr)
55 {
56 // Get the next font in the iteration.
57 status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef );
58 if(status == noErr)
59 {
60 #ifndef __LP64__
61 // TODO CS : Find replacement
62 // added CS : avoid showing fonts that won't be displayable
63 FMFontStyle intrinsicStyle = 0 ;
64 FMFont fontInstance ;
65 FMFontFamily fmFamily = FMGetFontFamilyFromATSFontFamilyRef( theATSFontFamilyRef );
66 status = FMGetFontFromFontFamilyInstance( fmFamily , 0 , &fontInstance , &intrinsicStyle);
67 if ( status != noErr )
68 {
69 status = noErr;
70 continue ;
71 }
72 #endif
73 if ( encoding != wxFONTENCODING_SYSTEM )
74 {
75 TextEncoding fontFamiliyEncoding = ATSFontFamilyGetEncoding(theATSFontFamilyRef) ;
76 if ( fontFamiliyEncoding != macEncoding )
77 continue ;
78 }
79
80 // TODO: determine fixed widths ...
81
82 CFStringRef theName = NULL;
83 ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
84 wxMacCFStringHolder cfName(theName) ;
85 fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding()));
86 }
87 else if (status == kATSIterationScopeModified) // Make sure the font database hasnÕt changed.
88 {
89 // reset the iterator
90 status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
91 kATSOptionFlagsUnRestrictedScope,
92 &theFontFamilyIterator);
93 fontFamilies.Clear() ;
94 }
95 }
96 ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
97
98 for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
99 {
100 if ( OnFacename( fontFamilies[i] ) == false )
101 break ;
102 }
103
104 return true;
105 }
106
107 bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
108 {
109 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
110
111 return true;
112 }
113
114 #endif // wxUSE_FONTMAP