summaryrefslogtreecommitdiffstats
path: root/libass/ass_fontselect.c
diff options
context:
space:
mode:
authorGrigori Goronzy <greg@chown.ath.cx>2015-06-14 03:11:50 +0200
committerGrigori Goronzy <greg@chown.ath.cx>2015-07-10 10:43:16 +0200
commit00f0df78deb9d7451617ffdc3c374cf2af820bed (patch)
tree46008b9c0f385a9a2008e1eb82cdbd801e131a7a /libass/ass_fontselect.c
parent9f62fd8b374235b98a325b6a903d49b2f6bb4cf3 (diff)
downloadlibass-00f0df78deb9d7451617ffdc3c374cf2af820bed.tar.bz2
libass-00f0df78deb9d7451617ffdc3c374cf2af820bed.tar.xz
fontselect: add fallback handling with callback
If we can't find a matching font face (with glyph coverage), ask the default font provider for a fallback family. The callback is optional.
Diffstat (limited to 'libass/ass_fontselect.c')
-rw-r--r--libass/ass_fontselect.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c
index 8c96e61..449f1cc 100644
--- a/libass/ass_fontselect.c
+++ b/libass/ass_fontselect.c
@@ -566,6 +566,7 @@ char *ass_font_select(ASS_FontSelector *priv, ASS_Library *library,
const char *family = font->desc.family;
unsigned bold = font->desc.bold;
unsigned italic = font->desc.italic;
+ ASS_FontProvider *default_provider = priv->default_provider;
if (family && *family)
res = select_font(priv, library, family, bold, italic, index,
@@ -580,6 +581,22 @@ char *ass_font_select(ASS_FontSelector *priv, ASS_Library *library,
family, bold, italic, res, *index, *postscript_name);
}
+ if (!res && default_provider && default_provider->funcs.fallback_font) {
+ ASS_FontProviderMetaData meta;
+ meta.families = &family;
+ meta.weight = bold;
+ meta.slant = italic;
+ meta.width = 100;
+ char *fallback_family = default_provider->funcs.fallback_font(
+ default_provider->priv, &meta, code);
+
+ if (fallback_family) {
+ res = select_font(priv, library, fallback_family, bold, italic,
+ index, postscript_name, uid, data, code);
+ free(fallback_family);
+ }
+ }
+
if (!res && priv->path_default) {
res = strdup(priv->path_default);
*index = priv->index_default;
@@ -592,6 +609,8 @@ char *ass_font_select(ASS_FontSelector *priv, ASS_Library *library,
// This code path is reached when the script uses glyphs not
// available in the previous fonts (or no font is matched), and
// the ASS_FontProvider used provides only the MatchFontsFunc callback
+ // and no GetFallbackFunc callback. As a last resort, try a builtin
+ // list of fallback families.
for (int i = 0; fallback_fonts[i] && !res; i++) {
res = select_font(priv, library, fallback_fonts[i], bold,
italic, index, postscript_name, uid, data, code);