]> git.saurik.com Git - wxWidgets.git/blob - src/osx/core/fontenum.cpp
Fix wxHTMLDataObject compilation and memory leaks.
[wxWidgets.git] / src / osx / core / fontenum.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/core/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_FONTENUM
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/osx/private.h"
29
30 // ----------------------------------------------------------------------------
31 // wxFontEnumerator
32 // ----------------------------------------------------------------------------
33
34 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
35 bool fixedWidthOnly)
36 {
37 if ( fixedWidthOnly )
38 {
39 wxFAIL_MSG( "enumerating only fixed width fonts not supported" );
40 return false;
41 }
42
43 wxArrayString fontFamilies ;
44
45 #if wxOSX_USE_ATSU_TEXT || wxOSX_USE_CORE_TEXT
46
47 //
48 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
49 //
50
51 ATSFontFamilyIterator theFontFamilyIterator = NULL;
52 ATSFontFamilyRef theATSFontFamilyRef = 0;
53 OSStatus status = noErr;
54
55 // Create the iterator
56 status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil,
57 kATSOptionFlagsUnRestrictedScope,
58 &theFontFamilyIterator );
59
60 wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ;
61
62 while (status == noErr)
63 {
64 // Get the next font in the iteration.
65 status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef );
66 if(status == noErr)
67 {
68 if ( encoding != wxFONTENCODING_SYSTEM )
69 {
70 TextEncoding fontFamiliyEncoding = ATSFontFamilyGetEncoding(theATSFontFamilyRef) ;
71 if ( fontFamiliyEncoding != macEncoding )
72 continue ;
73 }
74
75 // TODO: determine fixed widths ...
76
77 CFStringRef theName = NULL;
78 ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
79 wxCFStringRef cfName(theName) ;
80 fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding()));
81 }
82 else if (status == kATSIterationScopeModified) // Make sure the font database hasn't changed.
83 {
84 // reset the iterator
85 status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
86 kATSOptionFlagsUnRestrictedScope,
87 &theFontFamilyIterator);
88 fontFamilies.Clear() ;
89 }
90 }
91 ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
92 #endif
93
94 for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
95 {
96 if ( OnFacename( fontFamilies[i] ) == false )
97 break ;
98 }
99
100 return true;
101 }
102
103 bool wxFontEnumerator::EnumerateEncodings(const wxString& WXUNUSED(family))
104 {
105 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
106
107 return true;
108 }
109
110 #endif // wxUSE_FONTENUM