summaryrefslogtreecommitdiffstats
path: root/libass/ass_coretext.c
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-11-02 12:07:07 +0100
committerGrigori Goronzy <greg@chown.ath.cx>2015-07-10 10:42:40 +0200
commit9014b275e9e90d796bee95249a6059e4a55f3cf9 (patch)
treecb8972dc534a88fd4dc2bf3ee88a0735cdc53035 /libass/ass_coretext.c
parentd9585a81add0a41f6a59f3c7f95bcc6182732059 (diff)
downloadlibass-9014b275e9e90d796bee95249a6059e4a55f3cf9.tar.bz2
libass-9014b275e9e90d796bee95249a6059e4a55f3cf9.tar.xz
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.
Diffstat (limited to 'libass/ass_coretext.c')
-rw-r--r--libass/ass_coretext.c15
1 files changed, 10 insertions, 5 deletions
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);
}