From 9014b275e9e90d796bee95249a6059e4a55f3cf9 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 2 Nov 2013 12:07:07 +0100 Subject: fontselect: coretext: allow selection based on PostScript name Up until now fontselect used the face index to identify which font to load from a font collection. While this pretty convenient when using something freetype based like fontconfig, it seems to be somewhat freetype specific. CoreText uses the PostScript name as the unique identifier of a font. This commit allows to use that instead of the index to decide which face to open with FT_New_Face. To use the PostScript name the provider must return a -1 index and the PostScript name. --- libass/ass_coretext.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'libass/ass_coretext.c') diff --git a/libass/ass_coretext.c b/libass/ass_coretext.c index f970226..802b511 100644 --- a/libass/ass_coretext.c +++ b/libass/ass_coretext.c @@ -32,7 +32,7 @@ static char *cfstr2buf(CFStringRef string) return strdup(buf_ptr); } else { size_t buf_len = CFStringGetLength(string) + 1; - char *buf = calloc(buf_len, sizeof(char)); + char *buf = malloc(buf_len); CFStringGetCString(string, buf, buf_len, kCFStringEncodingUTF8); return buf; } @@ -153,14 +153,15 @@ static void scan_fonts(ASS_Library *lib, ASS_FontProvider *provider) { ASS_FontProviderMetaData meta; char *families[1]; - char *fullnames[2]; + char *identifiers[1]; + char *fullnames[1]; CTFontCollectionRef coll = CTFontCollectionCreateFromAvailableFonts(NULL); CFArrayRef fontsd = CTFontCollectionCreateMatchingFontDescriptors(coll); for (int i = 0; i < CFArrayGetCount(fontsd); i++) { CTFontDescriptorRef fontd = CFArrayGetValueAtIndex(fontsd, i); - int index = 0; + int index = -1; char *path = get_font_file(fontd); if (strcmp("", path) == 0) { @@ -175,13 +176,15 @@ static void scan_fonts(ASS_Library *lib, ASS_FontProvider *provider) get_name(fontd, kCTFontFamilyNameAttribute, families, &meta.n_family); meta.families = families; + int zero = 0; + get_name(fontd, kCTFontNameAttribute, identifiers, &zero); get_name(fontd, kCTFontDisplayNameAttribute, fullnames, &meta.n_fullname); - get_name(fontd, kCTFontNameAttribute, fullnames, &meta.n_fullname); meta.fullnames = fullnames; CFCharacterSetRef chset = CTFontDescriptorCopyAttribute(fontd, kCTFontCharacterSetAttribute); - ass_font_provider_add_font(provider, &meta, path, index, (void*)chset); + ass_font_provider_add_font(provider, &meta, path, index, + identifiers[0], (void*)chset); for (int j = 0; j < meta.n_family; j++) free(meta.families[j]); @@ -189,6 +192,8 @@ static void scan_fonts(ASS_Library *lib, ASS_FontProvider *provider) for (int j = 0; j < meta.n_fullname; j++) free(meta.fullnames[j]); + free(identifiers[0]); + free(path); } -- cgit v1.2.3