diff options
author | Oleg Oshmyan <chortos@inbox.lv> | 2021-05-23 05:19:28 +0300 |
---|---|---|
committer | Oleg Oshmyan <chortos@inbox.lv> | 2021-06-07 13:42:02 +0200 |
commit | 6fc9855dac44699242ded580040838da032c3a9d (patch) | |
tree | 0dccf903d7064c3c8374213c7c76281bddcee7cd /libass/ass_coretext.c | |
parent | bfffc82c88b55071901f7d00ebe3e66168cd5a6d (diff) | |
download | libass-6fc9855dac44699242ded580040838da032c3a9d.tar.bz2 libass-6fc9855dac44699242ded580040838da032c3a9d.tar.xz |
fontselect, coretext: match whole extended family on fallback
Currently implemented only for coretext,
but other providers may/should add this later.
This improves fallback font choice by considering the whole extended family.
This also fixes remaining cases of Core Text fallback failure caused by
differences among the names recognized by Core Text, the name we choose
to return from get_fallback, and the names we seek in find_font.
This partly reverts commit 152d0484e98f118d01987138695cf40579c9e297.
This fixes https://github.com/libass/libass/issues/512.
Diffstat (limited to 'libass/ass_coretext.c')
-rw-r--r-- | libass/ass_coretext.c | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/libass/ass_coretext.c b/libass/ass_coretext.c index f331639..4041046 100644 --- a/libass/ass_coretext.c +++ b/libass/ass_coretext.c @@ -129,21 +129,30 @@ static char *get_name(CTFontDescriptorRef fontd, CFStringRef attr) static bool fill_family_name(CTFontDescriptorRef fontd, ASS_FontProviderMetaData *info) { - if (info->n_family) - return true; - char *family_name = get_name(fontd, kCTFontFamilyNameAttribute); if (!family_name) return false; - info->families = malloc(sizeof(char *)); - if (!info->families) { - free(family_name); - return false; + info->extended_family = family_name; + + if (!info->n_family) { + family_name = strdup(family_name); + if (!family_name) { + free(info->extended_family); + return false; + } + + info->families = malloc(sizeof(char *)); + if (!info->families) { + free(family_name); + free(info->extended_family); + return false; + } + + info->families[0] = family_name; + info->n_family++; } - info->families[0] = family_name; - info->n_family++; return true; } @@ -196,6 +205,7 @@ static void process_descriptors(ASS_Library *lib, FT_Library ftlib, free(meta.fullnames); free(meta.postscript_name); + free(meta.extended_family); free(path); } @@ -280,8 +290,6 @@ cleanup: static char *get_fallback(void *priv, ASS_Library *lib, const char *family, uint32_t codepoint) { - FT_Library ftlib = priv; - CFStringRef name = CFStringCreateWithBytes( 0, (UInt8 *)family, strlen(family), kCFStringEncodingUTF8, false); if (!name) @@ -308,33 +316,15 @@ static char *get_fallback(void *priv, ASS_Library *lib, if (!fb) return NULL; - CTFontDescriptorRef fontd = CTFontCopyFontDescriptor(fb); + CFStringRef cffamily = CTFontCopyFamilyName(fb); CFRelease(fb); - if (!fontd) + if (!cffamily) return NULL; - char *res_name = NULL; - char *path = NULL; - ASS_FontProviderMetaData meta = {0}; - if (get_font_info_ct(lib, ftlib, fontd, &path, &meta)) - res_name = meta.families[0]; - - CFRelease(fontd); - - for (int i = 1 /* skip res_name */; i < meta.n_family; i++) - free(meta.families[i]); - - for (int i = 0; i < meta.n_fullname; i++) - free(meta.fullnames[i]); - - free(meta.families); - free(meta.fullnames); - - free(meta.postscript_name); - - free(path); + char *res_family = cfstr2buf(cffamily); + CFRelease(cffamily); - return res_name; + return res_family; } static void get_substitutions(void *priv, const char *name, |