]> git.saurik.com Git - wxWidgets.git/blame - src/osx/core/fontenum.cpp
Fix wxHtmlHelpData::SetTempDir() to behave correctly without trailing slash.
[wxWidgets.git] / src / osx / core / fontenum.cpp
CommitLineData
489468fe 1///////////////////////////////////////////////////////////////////////////////
96dabe43 2// Name: src/osx/core/fontenum.cpp
489468fe
SC
3// Purpose: wxFontEnumerator class for MacOS
4// Author: Stefan Csomor
5// Modified by:
6// Created: 04/01/98
489468fe
SC
7// Copyright: (c) Stefan Csomor
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#if wxUSE_FONTENUM
15
16#include "wx/fontenum.h"
17
18#ifndef WX_PRECOMP
19 #include "wx/font.h"
20 #include "wx/intl.h"
21#endif
22
23#include "wx/fontutil.h"
24#include "wx/fontmap.h"
25#include "wx/encinfo.h"
26
1f0c8f31 27#include "wx/osx/private.h"
489468fe
SC
28
29// ----------------------------------------------------------------------------
30// wxFontEnumerator
31// ----------------------------------------------------------------------------
32
8ffac5b0
SC
33#if wxOSX_USE_IPHONE
34extern CFArrayRef CopyAvailableFontFamilyNames();
35#endif
36
489468fe
SC
37bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
38 bool fixedWidthOnly)
39{
63660cba 40 wxArrayString fontFamilies ;
489468fe
SC
41
42 wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ;
63660cba
SC
43
44#if wxOSX_USE_CORE_TEXT
489468fe 45 {
63660cba 46 CFArrayRef cfFontFamilies = nil;
8ffac5b0
SC
47
48#if wxOSX_USE_COCOA_OR_CARBON
63660cba
SC
49#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
50 if ( UMAGetSystemVersion() >= 0x1060 )
51 cfFontFamilies = CTFontManagerCopyAvailableFontFamilyNames();
52 else
53#endif
489468fe 54 {
d1a00499 55#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
63660cba
SC
56 //
57 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
58 //
59
60 CFMutableArrayRef atsfontnames = CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks);;
61
62 ATSFontFamilyIterator theFontFamilyIterator = NULL;
63 ATSFontFamilyRef theATSFontFamilyRef = 0;
64 OSStatus status = noErr;
65
66 // Create the iterator
67 status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil,
68 kATSOptionFlagsUnRestrictedScope,
69 &theFontFamilyIterator );
70
71 while (status == noErr)
489468fe 72 {
63660cba
SC
73 // Get the next font in the iteration.
74 status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef );
75 if(status == noErr)
76 {
77 CFStringRef theName = NULL;
78 ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
79 CFArrayAppendValue(atsfontnames, theName);
80 CFRelease(theName);
81
82 }
83 else if (status == kATSIterationScopeModified) // Make sure the font database hasn't changed.
84 {
85 // reset the iterator
86 status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
87 kATSOptionFlagsUnRestrictedScope,
88 &theFontFamilyIterator);
89 CFArrayRemoveAllValues(atsfontnames);
90 }
489468fe 91 }
63660cba
SC
92 ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
93 cfFontFamilies = atsfontnames;
94#endif
489468fe 95 }
8ffac5b0
SC
96#elif wxOSX_USE_IPHONE
97 cfFontFamilies = CopyAvailableFontFamilyNames();
98#endif
63660cba
SC
99
100 CFIndex count = CFArrayGetCount(cfFontFamilies);
101 for(CFIndex i = 0; i < count; i++)
489468fe 102 {
63660cba
SC
103 CFStringRef fontName = (CFStringRef)CFArrayGetValueAtIndex(cfFontFamilies, i);
104
105 if ( encoding != wxFONTENCODING_SYSTEM || fixedWidthOnly)
106 {
107 wxCFRef<CTFontRef> font(CTFontCreateWithName(fontName, 12.0, NULL));
108 if ( encoding != wxFONTENCODING_SYSTEM )
109 {
110 CFStringEncoding fontFamiliyEncoding = CTFontGetStringEncoding(font);
111 if ( fontFamiliyEncoding != macEncoding )
112 continue;
113 }
114
115 if ( fixedWidthOnly )
116 {
117 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font);
118 if ( (traits & kCTFontMonoSpaceTrait) == 0 )
119 continue;
120 }
121
122 }
123
124 wxCFStringRef cfName(wxCFRetain(fontName)) ;
125 fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding()));
489468fe 126 }
63660cba
SC
127
128 CFRelease(cfFontFamilies);
489468fe 129 }
489468fe 130#endif
489468fe
SC
131 for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
132 {
133 if ( OnFacename( fontFamilies[i] ) == false )
134 break ;
135 }
136
137 return true;
138}
139
140bool wxFontEnumerator::EnumerateEncodings(const wxString& WXUNUSED(family))
141{
142 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
143
144 return true;
145}
146
147#endif // wxUSE_FONTENUM