diff options
author | Grigori Goronzy <greg@blackbox> | 2010-06-26 02:17:03 +0200 |
---|---|---|
committer | Grigori Goronzy <greg@blackbox> | 2010-06-26 02:21:08 +0200 |
commit | 457b56333b5a4dcab972c356d8e8e49eecc2df6d (patch) | |
tree | 7c1574d309b0d9027c28078e5e0636298d5f6c7c | |
parent | 7ac975641bf4364d7c9b35ecead5b9c2a87468d6 (diff) | |
download | libass-457b56333b5a4dcab972c356d8e8e49eecc2df6d.tar.bz2 libass-457b56333b5a4dcab972c356d8e8e49eecc2df6d.tar.xz |
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.
-rw-r--r-- | libass/ass_fontconfig.c | 23 |
1 files 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; |