]> granicus.if.org Git - libass/commitdiff
fontconfig: handle fallback corner cases
authorGrigori Goronzy <greg@chown.ath.cx>
Sun, 6 Sep 2015 23:29:27 +0000 (01:29 +0200)
committerGrigori Goronzy <greg@chown.ath.cx>
Mon, 7 Sep 2015 00:18:29 +0000 (02:18 +0200)
If no particular codepoint is requested (codepoint == 0), just return
the first font family. Additionally, handle fontconfig errors, albeit
they're unlikely to happen.

libass/ass_fontconfig.c

index e97102bbc0bb29717e3082fddd240b00c2f6a635..d91dc6ce056614a58010da102265d62768755a56 100644 (file)
@@ -177,6 +177,17 @@ static char *get_fallback(void *priv, const char *family, uint32_t codepoint)
     if (!fc->fallbacks || fc->fallbacks->nfont == 0)
         return NULL;
 
+    if (codepoint == 0) {
+        char *family = NULL;
+        result = FcPatternGetString(fc->fallbacks->fonts[0], FC_FAMILY, 0,
+                (FcChar8 **)&family);
+        if (result == FcResultMatch) {
+            return strdup(family);
+        } else {
+            return NULL;
+        }
+    }
+
     // fallback_chars is the union of all available charsets, so
     // if we can't find the glyph in there, the system does not
     // have any font to render this glyph.
@@ -194,8 +205,11 @@ static char *get_fallback(void *priv, const char *family, uint32_t codepoint)
             char *family = NULL;
             result = FcPatternGetString(pattern, FC_FAMILY, 0,
                     (FcChar8 **)&family);
-            family = strdup(family);
-            return family;
+            if (result == FcResultMatch) {
+                return strdup(family);
+            } else {
+                return NULL;
+            }
         }
     }