From 30985285382527b08cc627873ba8795124c34862 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 5 Dec 2013 19:07:02 +0100 Subject: [PATCH] coretext: also lazy load fonts based on Family and PostScript names Previously, the lazy load of fonts was only using display name. Also use the other names available through the CoreText API (FamilyName and PostScriptName). --- libass/ass_coretext.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/libass/ass_coretext.c b/libass/ass_coretext.c index 75a5514..ad05443 100644 --- a/libass/ass_coretext.c +++ b/libass/ass_coretext.c @@ -219,17 +219,26 @@ static void scan_fonts(ASS_Library *lib, ASS_FontProvider *provider) static void match_fonts(ASS_Library *lib, ASS_FontProvider *provider, char *name) { - void *descr_ary[1]; + const size_t attributes_n = 3; + CTFontDescriptorRef ctdescrs[attributes_n]; + CFMutableDictionaryRef cfattrs[attributes_n]; + CFStringRef attributes[attributes_n] = { + kCTFontFamilyNameAttribute, + kCTFontDisplayNameAttribute, + kCTFontNameAttribute, + }; CFStringRef cfname = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8); - CFMutableDictionaryRef cfattrs = CFDictionaryCreateMutable(NULL, 0, 0, 0); - CFDictionaryAddValue(cfattrs, kCTFontDisplayNameAttribute, cfname); - CTFontDescriptorRef ctdescr = CTFontDescriptorCreateWithAttributes(cfattrs); - descr_ary[0] = (void *)ctdescr; + for (int i = 0; i < attributes_n; i++) { + cfattrs[i] = CFDictionaryCreateMutable(NULL, 0, 0, 0); + CFDictionaryAddValue(cfattrs[i], attributes[i], cfname); + ctdescrs[i] = CTFontDescriptorCreateWithAttributes(cfattrs[i]); + } + CFArrayRef descriptors = - CFArrayCreate(NULL, (const void **)&descr_ary, 1, NULL); + CFArrayCreate(NULL, (const void **)&ctdescrs, attributes_n, NULL); CTFontCollectionRef ctcoll = CTFontCollectionCreateWithFontDescriptors(descriptors, 0); @@ -242,8 +251,12 @@ static void match_fonts(ASS_Library *lib, ASS_FontProvider *provider, if (fontsd) CFRelease(fontsd); CFRelease(ctcoll); - CFRelease(cfattrs); - CFRelease(ctdescr); + + for (int i = 0; i < attributes_n; i++) { + CFRelease(cfattrs[i]); + CFRelease(ctdescrs[i]); + } + CFRelease(descriptors); CFRelease(cfname); } -- 2.40.0