From 6cf20043f5fa7c6aacf3abd49d94b350a24f6646 Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Mon, 7 Sep 2015 01:29:27 +0200 Subject: fontconfig: handle fallback corner cases 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 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libass/ass_fontconfig.c b/libass/ass_fontconfig.c index e97102b..d91dc6c 100644 --- a/libass/ass_fontconfig.c +++ b/libass/ass_fontconfig.c @@ -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; + } } } -- cgit v1.2.3