From 457b56333b5a4dcab972c356d8e8e49eecc2df6d Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Sat, 26 Jun 2010 02:17:03 +0200 Subject: Improve fullname matching Only match outline fonts and take slant and weight into consideration. This matches all font faces which have at least the slant/weight that is requested. This fixes issue 23; however, corner cases can be constructed in which wrong fonts will be matched, if multiple slant/weight variants of the same font exist, but that is very unlikely in practice. --- libass/ass_fontconfig.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/libass/ass_fontconfig.c b/libass/ass_fontconfig.c index b1686ff..dac2f05 100644 --- a/libass/ass_fontconfig.c +++ b/libass/ass_fontconfig.c @@ -57,11 +57,14 @@ struct fc_instance { * * \param lib library instance * \param priv fontconfig instance - * \param family font family + * \param family font fullname + * \param bold weight attribute + * \param italic italic attribute * \return font set */ -static FcFontSet *match_fullname(ASS_Library *lib, FCInstance *priv, - const char *family) +static FcFontSet * +match_fullname(ASS_Library *lib, FCInstance *priv, const char *family, + unsigned bold, unsigned italic) { FcFontSet *sets[2]; FcFontSet *result = FcFontSetCreate(); @@ -79,9 +82,19 @@ static FcFontSet *match_fullname(ASS_Library *lib, FCInstance *priv, for (fi = 0; fi < set->nfont; fi++) { FcPattern *pat = set->fonts[fi]; char *fullname; - int pi = 0; + int pi = 0, at; + FcBool ol; while (FcPatternGetString(pat, FC_FULLNAME, pi++, (FcChar8 **) &fullname) == FcResultMatch) + if (FcPatternGetBool(pat, FC_OUTLINE, 0, &ol) != FcResultMatch + || ol != FcTrue) + continue; + if (FcPatternGetInteger(pat, FC_SLANT, 0, &at) != FcResultMatch + || at < italic) + continue; + if (FcPatternGetInteger(pat, FC_WEIGHT, 0, &at) != FcResultMatch + || at < bold) + continue; if (strcasecmp(fullname, family) == 0) { FcFontSetAdd(result, FcPatternDuplicate(pat)); break; @@ -168,7 +181,7 @@ static char *select_font(ASS_Library *library, FCInstance *priv, goto error; fsorted = FcFontSort(priv->config, pat, FcTrue, NULL, &result); - ffullname = match_fullname(library, priv, family); + ffullname = match_fullname(library, priv, family, bold, italic); if (!fsorted || !ffullname) goto error; -- cgit v1.2.3