From e95626628eab9a892047c60e4b9926ab50ce1bd4 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 9 Dec 2013 19:09:09 +0100 Subject: fontselect: use fallback fonts when querying font providers 51f9e80b added a MatchFontsFunc callback which allows to lookup font names directly on the font provider. This approach broke support for font fallback which worked only with lookups from libass in-memory font database. This commit moves the font fallback code in the font lookup function, so that it is available for all font providers. --- libass/ass_fontselect.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'libass') diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c index 52ef192..f804c94 100644 --- a/libass/ass_fontselect.c +++ b/libass/ass_fontselect.c @@ -371,7 +371,6 @@ static unsigned font_info_similarity(ASS_FontInfo *a, ASS_FontInfo *req) { int i, j; unsigned similarity = 0; - const char **fallback = fallback_fonts; // compare fullnames // a matching fullname is very nice and instantly drops the score to zero @@ -392,15 +391,6 @@ static unsigned font_info_similarity(ASS_FontInfo *a, ASS_FontInfo *req) } } - // nothing found? Try fallback fonts - while (similarity > 0 && *fallback) { - for (i = 0; i < a->n_family; i++) { - if (strcmp(a->families[i], *fallback) == 0) - similarity = 5000; - } - fallback++; - } - // compare slant similarity += ABS(a->slant - req->slant); @@ -571,15 +561,18 @@ char *ass_font_select(ASS_FontSelector *priv, ASS_Library *library, res, *index, *postscript_name); } - // FIXME: not sure if that is needed, we cannot reach this path at the - // moment, either select_font returns or a font or the default one is used if (!res) { - res = select_font(priv, library, "Arial", bold, italic, - index, postscript_name, uid, data, code); - if (res) - ass_msg(library, MSGL_WARN, "fontselect: Using 'Arial' " - "font family: (%s, %d, %d) -> %s, %d, %s", family, bold, - italic, res, *index, *postscript_name); + // 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 + 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); + if (res) + ass_msg(library, MSGL_WARN, "fontselect: Using fallback " + "font family: (%s, %d, %d) -> %s, %d, %s", + family, bold, italic, res, *index, *postscript_name); + } } if (res) -- cgit v1.2.3