]> granicus.if.org Git - libass/commitdiff
fontselect: use fallback fonts when querying font providers
authorStefano Pigozzi <stefano.pigozzi@gmail.com>
Mon, 9 Dec 2013 18:09:09 +0000 (19:09 +0100)
committerGrigori Goronzy <greg@chown.ath.cx>
Fri, 10 Jul 2015 08:42:40 +0000 (10:42 +0200)
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

index 52ef192b258076799d13f164493ad113adb1383e..f804c94f75ea04ba4817c11243e33b7951d2c5e2 100644 (file)
@@ -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)