as we always have CoreText available under 10.5+, we can properly determine fixed widths fonts, also use latest CoreText API if available
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71761 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -34,63 +34,93 @@
|
||||
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 (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) && wxOSX_USE_ATSU_TEXT
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
|
||||
cfFontFamilies = atsfontnames;
|
||||
#endif
|
||||
}
|
||||
|
||||
CFIndex count = CFArrayGetCount(cfFontFamilies);
|
||||
for(CFIndex i = 0; i < count; i++)
|
||||
{
|
||||
CFStringRef fontName = (CFStringRef)CFArrayGetValueAtIndex(cfFontFamilies, i);
|
||||
|
||||
// TODO: determine fixed widths ...
|
||||
|
||||
CFStringRef theName = NULL;
|
||||
ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
|
||||
wxCFStringRef cfName(theName) ;
|
||||
if ( encoding != wxFONTENCODING_SYSTEM || fixedWidthOnly)
|
||||
{
|
||||
wxCFRef<CTFontRef> 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()));
|
||||
}
|
||||
else if (status == kATSIterationScopeModified) // Make sure the font database hasn't changed.
|
||||
{
|
||||
// reset the iterator
|
||||
status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
|
||||
kATSOptionFlagsUnRestrictedScope,
|
||||
&theFontFamilyIterator);
|
||||
fontFamilies.Clear() ;
|
||||
}
|
||||
|
||||
CFRelease(cfFontFamilies);
|
||||
}
|
||||
ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
|
||||
#endif
|
||||
|
||||
for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
|
||||
{
|
||||
if ( OnFacename( fontFamilies[i] ) == false )
|
||||
|
Reference in New Issue
Block a user