X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2432e3956362ae0a21d448b8f9bf22fbeea96d4d..3678169caab0f713415414dce013a638305f3cce:/src/osx/core/fontenum.cpp diff --git a/src/osx/core/fontenum.cpp b/src/osx/core/fontenum.cpp index f6ff151acb..3d6c0b5c33 100644 --- a/src/osx/core/fontenum.cpp +++ b/src/osx/core/fontenum.cpp @@ -31,66 +31,104 @@ // wxFontEnumerator // ---------------------------------------------------------------------------- +#if wxOSX_USE_IPHONE +extern CFArrayRef CopyAvailableFontFamilyNames(); +#endif + bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, bool fixedWidthOnly) { - if ( fixedWidthOnly ) - { - wxFAIL_MSG( "enumerating only fixed width fonts not supported" ); - return false; - } - - wxArrayString fontFamilies ; - -#if wxOSX_USE_ATSU_TEXT || wxOSX_USE_CORE_TEXT - - // - // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html - // - - ATSFontFamilyIterator theFontFamilyIterator = NULL; - ATSFontFamilyRef theATSFontFamilyRef = 0; - OSStatus status = noErr; - - // Create the iterator - status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil, - kATSOptionFlagsUnRestrictedScope, - &theFontFamilyIterator ); + wxArrayString fontFamilies ; wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ; - - while (status == noErr) + +#if wxOSX_USE_CORE_TEXT { - // Get the next font in the iteration. - status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef ); - if(status == noErr) + CFArrayRef cfFontFamilies = nil; + +#if wxOSX_USE_COCOA_OR_CARBON +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) + if ( UMAGetSystemVersion() >= 0x1060 ) + cfFontFamilies = CTFontManagerCopyAvailableFontFamilyNames(); + else +#endif { - if ( encoding != wxFONTENCODING_SYSTEM ) +#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6) + // + // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html + // + + CFMutableArrayRef atsfontnames = CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks);; + + ATSFontFamilyIterator theFontFamilyIterator = NULL; + ATSFontFamilyRef theATSFontFamilyRef = 0; + OSStatus status = noErr; + + // Create the iterator + status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil, + kATSOptionFlagsUnRestrictedScope, + &theFontFamilyIterator ); + + while (status == noErr) { - TextEncoding fontFamiliyEncoding = ATSFontFamilyGetEncoding(theATSFontFamilyRef) ; - if ( fontFamiliyEncoding != macEncoding ) - continue ; + // Get the next font in the iteration. + status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef ); + if(status == noErr) + { + CFStringRef theName = NULL; + ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName); + CFArrayAppendValue(atsfontnames, theName); + CFRelease(theName); + + } + else if (status == kATSIterationScopeModified) // Make sure the font database hasn't changed. + { + // reset the iterator + status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil, + kATSOptionFlagsUnRestrictedScope, + &theFontFamilyIterator); + CFArrayRemoveAllValues(atsfontnames); + } } - - // TODO: determine fixed widths ... - - CFStringRef theName = NULL; - ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName); - wxCFStringRef cfName(theName) ; - fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding())); + ATSFontFamilyIteratorRelease(&theFontFamilyIterator); + cfFontFamilies = atsfontnames; +#endif } - else if (status == kATSIterationScopeModified) // Make sure the font database hasn't changed. +#elif wxOSX_USE_IPHONE + cfFontFamilies = CopyAvailableFontFamilyNames(); +#endif + + CFIndex count = CFArrayGetCount(cfFontFamilies); + for(CFIndex i = 0; i < count; i++) { - // reset the iterator - status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil, - kATSOptionFlagsUnRestrictedScope, - &theFontFamilyIterator); - fontFamilies.Clear() ; + CFStringRef fontName = (CFStringRef)CFArrayGetValueAtIndex(cfFontFamilies, i); + + if ( encoding != wxFONTENCODING_SYSTEM || fixedWidthOnly) + { + wxCFRef font(CTFontCreateWithName(fontName, 12.0, NULL)); + if ( encoding != wxFONTENCODING_SYSTEM ) + { + CFStringEncoding fontFamiliyEncoding = CTFontGetStringEncoding(font); + if ( fontFamiliyEncoding != macEncoding ) + continue; + } + + if ( fixedWidthOnly ) + { + CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font); + if ( (traits & kCTFontMonoSpaceTrait) == 0 ) + continue; + } + + } + + wxCFStringRef cfName(wxCFRetain(fontName)) ; + fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding())); } + + CFRelease(cfFontFamilies); } - ATSFontFamilyIteratorRelease(&theFontFamilyIterator); #endif - for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i ) { if ( OnFacename( fontFamilies[i] ) == false )