[PATCH] gdi32: Get the font URL directly from the descriptor on macOS 10.6 and later.

Ken Thomases ken at codeweavers.com
Tue Nov 29 11:22:32 CST 2016


It's significantly faster than the roundabout way that's necessary for 10.5,
which is especially important for users with many fonts installed.  Issue
identified by Andrew Eikum.

Signed-off-by: Ken Thomases <ken at codeweavers.com>
---
 dlls/gdi32/freetype.c | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 0e82e5e..a5147b5 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -2933,33 +2933,40 @@ static void load_mac_fonts(void)
     for (i = 0; i < CFArrayGetCount(descs); i++)
     {
         CTFontDescriptorRef desc;
-        CTFontRef font;
-        ATSFontRef atsFont;
-        OSStatus status;
-        FSRef fsref;
         CFURLRef url;
         CFStringRef ext;
         CFStringRef path;
 
         desc = CFArrayGetValueAtIndex(descs, i);
 
-        /* CTFontDescriptor doesn't support kCTFontURLAttribute until 10.6, so
+#if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+        url = CTFontDescriptorCopyAttribute(desc, kCTFontURLAttribute);
+#else
+        /* CTFontDescriptor doesn't support kCTFontURLAttribute prior to 10.6, so
            we have to go CFFontDescriptor -> CTFont -> ATSFont -> FSRef -> CFURL. */
-        font = CTFontCreateWithFontDescriptor(desc, 0, NULL);
-        if (!font) continue;
-
-        atsFont = CTFontGetPlatformFont(font, NULL);
-        if (!atsFont)
         {
+            CTFontRef font;
+            ATSFontRef atsFont;
+            OSStatus status;
+            FSRef fsref;
+
+            font = CTFontCreateWithFontDescriptor(desc, 0, NULL);
+            if (!font) continue;
+
+            atsFont = CTFontGetPlatformFont(font, NULL);
+            if (!atsFont)
+            {
+                CFRelease(font);
+                continue;
+            }
+
+            status = ATSFontGetFileReference(atsFont, &fsref);
             CFRelease(font);
-            continue;
+            if (status != noErr) continue;
+
+            url = CFURLCreateFromFSRef(NULL, &fsref);
         }
-
-        status = ATSFontGetFileReference(atsFont, &fsref);
-        CFRelease(font);
-        if (status != noErr) continue;
-
-        url = CFURLCreateFromFSRef(NULL, &fsref);
+#endif
         if (!url) continue;
 
         ext = CFURLCopyPathExtension(url);
-- 
2.10.2




More information about the wine-patches mailing list