]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/core/fontenum.cpp
notify the event loop that synthesized events are on the queue, wait for them to...
[wxWidgets.git] / src / osx / core / fontenum.cpp
index c7e7376ff29b05731c2cc9b2bcbec0769523e0c9..3d6c0b5c335419133b55ffc12b4be82da8bb9595 100644 (file)
 // 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
         {
- #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 )
+#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)
             {
-                status = noErr;
-                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
+        }
+#elif wxOSX_USE_IPHONE
+        cfFontFamilies = CopyAvailableFontFamilyNames();
 #endif
-            if ( encoding != wxFONTENCODING_SYSTEM )
+        
+        CFIndex count = CFArrayGetCount(cfFontFamilies);
+        for(CFIndex i = 0; i < count; i++)
+        {
+            CFStringRef fontName = (CFStringRef)CFArrayGetValueAtIndex(cfFontFamilies, i);
+
+            if ( encoding != wxFONTENCODING_SYSTEM || fixedWidthOnly)
             {
-                TextEncoding fontFamiliyEncoding = ATSFontFamilyGetEncoding(theATSFontFamilyRef) ;
-                if ( fontFamiliyEncoding != macEncoding )
-                    continue ;
+                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;
+                }
+                
             }
-
-            // TODO: determine fixed widths ...
-
-            CFStringRef theName = NULL;
-            ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
-            wxCFStringRef cfName(theName) ;
+            
+            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 )