X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1089fc00cdf589ba187f3ae8d8c8cc0cb33da7f9..0c1cc9483ecba053bc9a0983a4a8d48898e334f2:/src/mac/carbon/fontenum.cpp diff --git a/src/mac/carbon/fontenum.cpp b/src/mac/carbon/fontenum.cpp index 564d76de69..233bdf3dd8 100644 --- a/src/mac/carbon/fontenum.cpp +++ b/src/mac/carbon/fontenum.cpp @@ -12,142 +12,109 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#if wxUSE_FONTMAP +#if wxUSE_FONTENUM + +#include "wx/fontenum.h" #ifndef WX_PRECOMP - #include "wx/font.h" + #include "wx/font.h" + #include "wx/intl.h" #endif -#include "wx/fontenum.h" #include "wx/fontutil.h" #include "wx/fontmap.h" -#include "wx/fontutil.h" #include "wx/encinfo.h" #include "wx/mac/private.h" - -class wxFontEnumeratorHelper -{ -public: - wxFontEnumeratorHelper(wxFontEnumerator *fontEnum); - - // control what exactly are we enumerating - bool SetEncoding(wxFontEncoding encoding); - void SetFixedOnly(bool fixedOnly) - { m_fixedOnly = fixedOnly; } - - // call to start enumeration - void DoEnumerate(); - -private: - // the object we forward calls to OnFont() to - wxFontEnumerator *m_fontEnum; - - // if != -1, enum only fonts which have this encoding - int m_charset; - - // if not empty, enum only the fonts with this facename - wxString m_facename; - - // if true, enum only fixed fonts - bool m_fixedOnly; -}; - -// ============================================================================ -// implementation -// ============================================================================ - // ---------------------------------------------------------------------------- -// wxFontEnumeratorHelper +// wxFontEnumerator // ---------------------------------------------------------------------------- -wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum) -{ - m_fontEnum = fontEnum; - m_charset = -1; - m_fixedOnly = false; -} - -bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding) +bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, + bool fixedWidthOnly) { - wxNativeEncodingInfo info; - if ( !wxGetNativeFontEncoding( encoding, &info ) ) + if ( fixedWidthOnly ) { - if ( !wxFontMapper::Get()->GetAltForEncoding( encoding, &info ) ) - // no such encodings at all - return false; + wxFAIL_MSG( "enumerating only fixed width fonts not supported" ); + return false; } - m_charset = info.charset; - m_facename = info.facename; + // + // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html + // - return true; -} + ATSFontFamilyIterator theFontFamilyIterator = NULL; + ATSFontFamilyRef theATSFontFamilyRef = 0; + OSStatus status = noErr; -void wxFontEnumeratorHelper::DoEnumerate() -{ - MenuHandle menu; - Str255 p_name; - short lines; + wxArrayString fontFamilies ; - menu = NewMenu( 32000, "\pFont" ); - AppendResMenu( menu, 'FONT' ); - lines = CountMenuItems( menu ); + // Create the iterator + status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil, + kATSOptionFlagsUnRestrictedScope, + &theFontFamilyIterator ); - for ( int i = 1; i < lines + 1; i ++ ) - { - GetMenuItemText( menu, i, p_name ); - wxString c_name = wxMacMakeStringFromPascal( p_name ); + wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ; -#if 0 - if ( m_fixedOnly ) + while (status == noErr) + { + // Get the next font in the iteration. + status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef ); + if(status == noErr) { - // check that it's a fixed pitch font: - // there is *no* error here: the flag name is misleading! - if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH ) - // not a fixed pitch font - return true; + #ifndef __LP64__ + // TODO CS : Find replacement + // added CS : avoid showing fonts that won't be displayable + FMFontStyle intrinsicStyle = 0 ; + FMFont fontInstance ; + FMFontFamily fmFamily = FMGetFontFamilyFromATSFontFamilyRef( theATSFontFamilyRef ); + status = FMGetFontFromFontFamilyInstance( fmFamily , 0 , &fontInstance , &intrinsicStyle); + if ( status != noErr ) + { + status = noErr; + continue ; + } +#endif + if ( encoding != wxFONTENCODING_SYSTEM ) + { + TextEncoding fontFamiliyEncoding = ATSFontFamilyGetEncoding(theATSFontFamilyRef) ; + if ( fontFamiliyEncoding != macEncoding ) + continue ; + } + + // TODO: determine fixed widths ... + + CFStringRef theName = NULL; + ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName); + wxCFStringRef cfName(theName) ; + fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding())); } - - if ( m_charset != -1 ) + else if (status == kATSIterationScopeModified) // Make sure the font database hasnÕt changed. { - // check that we have the right encoding - if ( lf->lfCharSet != m_charset ) - return true; + // reset the iterator + status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil, + kATSOptionFlagsUnRestrictedScope, + &theFontFamilyIterator); + fontFamilies.Clear() ; } -#endif - - m_fontEnum->OnFacename( c_name ); } + ATSFontFamilyIteratorRelease(&theFontFamilyIterator); - DisposeMenu( menu ); -} - -// ---------------------------------------------------------------------------- -// wxFontEnumerator -// ---------------------------------------------------------------------------- - -bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, - bool fixedWidthOnly) -{ - wxFontEnumeratorHelper fe(this); - if ( fe.SetEncoding(encoding) ) + for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i ) { - fe.SetFixedOnly(fixedWidthOnly); - - fe.DoEnumerate(); + if ( OnFacename( fontFamilies[i] ) == false ) + break ; } - // else: no such fonts, unknown encoding return true; } -bool wxFontEnumerator::EnumerateEncodings(const wxString& family) +bool wxFontEnumerator::EnumerateEncodings(const wxString& WXUNUSED(family)) { wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented")); return true; } -#endif +#endif // wxUSE_FONTENUM