X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/03e11df5470fd64d9d9a669d0b50b84c2d714736..4ccb5877f76c068ce600a7660bb1efc1e3e1c154:/src/mac/carbon/fontenum.cpp?ds=sidebyside diff --git a/src/mac/carbon/fontenum.cpp b/src/mac/carbon/fontenum.cpp index 14491d79e9..f74bbb43fc 100644 --- a/src/mac/carbon/fontenum.cpp +++ b/src/mac/carbon/fontenum.cpp @@ -1,174 +1,120 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: mac/fontenum.cpp +// Name: src/mac/carbon/fontenum.cpp // Purpose: wxFontEnumerator class for MacOS // Author: Stefan Csomor -// Modified by: +// Modified by: // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#ifdef __GNUG__ - #pragma implementation "fontenum.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#ifdef __BORLANDC__ - #pragma hdrstop -#endif +#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" // ---------------------------------------------------------------------------- -// private classes +// wxFontEnumerator // ---------------------------------------------------------------------------- -class wxFontEnumeratorHelper +bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, + bool fixedWidthOnly) { -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(); + if ( fixedWidthOnly ) + { + wxFAIL_MSG( "enumerating only fixed width fonts not supported" ); + return false; + } -private: - // the object we forward calls to OnFont() to - wxFontEnumerator *m_fontEnum; + // + // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html + // - // if != -1, enum only fonts which have this encoding - int m_charset; + ATSFontFamilyIterator theFontFamilyIterator = NULL; + ATSFontFamilyRef theATSFontFamilyRef = 0; + OSStatus status = noErr; - // if not empty, enum only the fonts with this facename - wxString m_facename; + wxArrayString fontFamilies ; - // if TRUE, enum only fixed fonts - bool m_fixedOnly; -}; -// ============================================================================ -// implementation -// ============================================================================ + // Create the iterator + status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil, + kATSOptionFlagsUnRestrictedScope, + &theFontFamilyIterator ); -// ---------------------------------------------------------------------------- -// wxFontEnumeratorHelper -// ---------------------------------------------------------------------------- + wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ; -wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum) -{ - m_fontEnum = fontEnum; - m_charset = -1; - m_fixedOnly = FALSE; -} - -bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding) -{ - wxNativeEncodingInfo info; - if ( !wxGetNativeFontEncoding(encoding, &info) ) + while (status == noErr) { - if ( !wxTheFontMapper->GetAltForEncoding(encoding, &info) ) + // Get the next font in the iteration. + status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef ); + if(status == noErr) + { + #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); + wxMacCFStringHolder cfName(theName) ; + fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding())); + } + else if (status == kATSIterationScopeModified) // Make sure the font database hasnÕt changed. { - // no such encodings at all - return FALSE; + // reset the iterator + status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil, + kATSOptionFlagsUnRestrictedScope, + &theFontFamilyIterator); + fontFamilies.Clear() ; } } - m_charset = info.charset; - m_facename = info.facename; + ATSFontFamilyIteratorRelease(&theFontFamilyIterator); - return TRUE; -} - -void wxFontEnumeratorHelper::DoEnumerate() -{ - MenuHandle menu ; - Str255 p_name ; - char c_name[256] ; - short lines ; - - menu = NewMenu( 32000 , "\pFont" ) ; - AppendResMenu( menu , 'FONT' ) ; - lines = CountMenuItems( menu ) ; - - for ( int i = 1 ; i < lines+1 ; i ++ ) - { - GetMenuItemText( menu , i , p_name ) ; -#if TARGET_CARBON - p2cstrcpy( c_name, p_name ) ; -#else - p2cstr( p_name ) ; - strcpy( c_name, (char *)p_name ) ; -#endif - /* - - if ( m_fixedOnly ) - { - // 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; - } - } - - if ( m_charset != -1 ) - { - // check that we have the right encoding - if ( lf->lfCharSet != m_charset ) - { - return TRUE; - } - } - - */ - m_fontEnum->OnFacename( c_name ) ; - } - 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; + return true; } -bool wxFontEnumerator::EnumerateEncodings(const wxString& family) +bool wxFontEnumerator::EnumerateEncodings(const wxString& WXUNUSED(family)) { - wxFAIL_MSG(wxT("TODO")); + wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented")); - return TRUE; + return true; } + +#endif // wxUSE_FONTENUM