summaryrefslogtreecommitdiffstats
path: root/libass/ass_fontselect.c
diff options
context:
space:
mode:
authorOleg Oshmyan <chortos@inbox.lv>2021-05-23 05:19:28 +0300
committerOleg Oshmyan <chortos@inbox.lv>2021-06-07 13:42:02 +0200
commit6fc9855dac44699242ded580040838da032c3a9d (patch)
tree0dccf903d7064c3c8374213c7c76281bddcee7cd /libass/ass_fontselect.c
parentbfffc82c88b55071901f7d00ebe3e66168cd5a6d (diff)
downloadlibass-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_fontselect.c')
-rw-r--r--libass/ass_fontselect.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c
index 3013f4a..ef79066 100644
--- a/libass/ass_fontselect.c
+++ b/libass/ass_fontselect.c
@@ -71,6 +71,8 @@ struct font_info {
char *postscript_name; // can be used as an alternative to index to
// identify a font inside a collection
+ char *extended_family;
+
// font source
ASS_FontProvider *provider;
@@ -235,6 +237,8 @@ static void ass_font_provider_free_fontinfo(ASS_FontInfo *info)
if (info->postscript_name)
free(info->postscript_name);
+ if (info->extended_family)
+ free(info->extended_family);
}
/**
@@ -334,6 +338,12 @@ ass_font_provider_add_font(ASS_FontProvider *provider,
goto error;
}
+ if (meta->extended_family) {
+ info->extended_family = strdup(meta->extended_family);
+ if (info->extended_family == NULL)
+ goto error;
+ }
+
if (path) {
info->path = strdup(path);
if (info->path == NULL)
@@ -423,12 +433,17 @@ static bool check_postscript(ASS_FontInfo *fi)
/**
* \brief Return whether the given font is in the given family.
*/
-static bool matches_family_name(ASS_FontInfo *f, const char *family)
+static bool matches_family_name(ASS_FontInfo *f, const char *family,
+ bool match_extended_family)
{
for (int i = 0; i < f->n_family; i++) {
if (ass_strcasecmp(f->families[i], family) == 0)
return true;
}
+ if (match_extended_family && f->extended_family) {
+ if (ass_strcasecmp(f->extended_family, family) == 0)
+ return true;
+ }
return false;
}
@@ -517,7 +532,8 @@ static bool check_glyph(ASS_FontInfo *fi, uint32_t code)
static char *
find_font(ASS_FontSelector *priv, ASS_Library *library,
- ASS_FontProviderMetaData meta, unsigned bold, unsigned italic,
+ ASS_FontProviderMetaData meta, bool match_extended_family,
+ unsigned bold, unsigned italic,
int *index, char **postscript_name, int *uid, ASS_FontStream *stream,
uint32_t code, bool *name_match)
{
@@ -542,7 +558,7 @@ find_font(ASS_FontSelector *priv, ASS_Library *library,
ASS_FontInfo *font = &priv->font_infos[x];
unsigned score = UINT_MAX;
- if (matches_family_name(font, fullname)) {
+ if (matches_family_name(font, fullname, match_extended_family)) {
// If there's a family match, compare font attributes
// to determine best match in that particular family
score = font_attributes_similarity(font, &req);
@@ -620,7 +636,8 @@ find_font(ASS_FontSelector *priv, ASS_Library *library,
}
static char *select_font(ASS_FontSelector *priv, ASS_Library *library,
- const char *family, unsigned bold, unsigned italic,
+ const char *family, bool match_extended_family,
+ unsigned bold, unsigned italic,
int *index, char **postscript_name, int *uid,
ASS_FontStream *stream, uint32_t code)
{
@@ -647,8 +664,9 @@ static char *select_font(ASS_FontSelector *priv, ASS_Library *library,
meta = default_meta;
}
- result = find_font(priv, library, meta, bold, italic, index,
- postscript_name, uid, stream, code, &name_match);
+ result = find_font(priv, library, meta, match_extended_family,
+ bold, italic, index, postscript_name, uid,
+ stream, code, &name_match);
// If no matching font was found, it might not exist in the font list
// yet. Call the match_fonts callback to fill in the missing fonts
@@ -662,8 +680,9 @@ static char *select_font(ASS_FontSelector *priv, ASS_Library *library,
library, default_provider,
meta.fullnames[i]);
}
- result = find_font(priv, library, meta, bold, italic, index,
- postscript_name, uid, stream, code, &name_match);
+ result = find_font(priv, library, meta, match_extended_family,
+ bold, italic, index, postscript_name, uid,
+ stream, code, &name_match);
}
// cleanup
@@ -699,11 +718,11 @@ char *ass_font_select(ASS_FontSelector *priv, ASS_Library *library,
ASS_FontProvider *default_provider = priv->default_provider;
if (family && *family)
- res = select_font(priv, library, family, bold, italic, index,
+ res = select_font(priv, library, family, false, bold, italic, index,
postscript_name, uid, data, code);
if (!res && priv->family_default) {
- res = select_font(priv, library, priv->family_default, bold,
+ res = select_font(priv, library, priv->family_default, false, bold,
italic, index, postscript_name, uid, data, code);
if (res)
ass_msg(library, MSGL_WARN, "fontselect: Using default "
@@ -720,7 +739,7 @@ char *ass_font_select(ASS_FontSelector *priv, ASS_Library *library,
default_provider->priv, library, search_family, code);
if (fallback_family) {
- res = select_font(priv, library, fallback_family, bold, italic,
+ res = select_font(priv, library, fallback_family, true, bold, italic,
index, postscript_name, uid, data, code);
free(fallback_family);
}