diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2013-12-05 19:07:02 +0100 |
---|---|---|
committer | Grigori Goronzy <greg@chown.ath.cx> | 2015-07-10 10:42:40 +0200 |
commit | 30985285382527b08cc627873ba8795124c34862 (patch) | |
tree | fea0c701e56ffaa9d259a9252a8279dafabfc727 | |
parent | b0776d353f8c3396165effd21e113c4f225daa0d (diff) | |
download | libass-30985285382527b08cc627873ba8795124c34862.tar.bz2 libass-30985285382527b08cc627873ba8795124c34862.tar.xz |
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).
-rw-r--r-- | libass/ass_coretext.c | 29 |
1 files 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); } |