From 6bb17b7e7b783844e66335a7293c82c93ea757d3 Mon Sep 17 00:00:00 2001 From: rcombs Date: Wed, 16 Sep 2020 23:36:20 -0500 Subject: ass_fontconfig: use FcWeightToOpenTypeDouble This provides higher precision in reported weights when using the fontconfig font provider. --- libass/ass_fontconfig.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'libass') diff --git a/libass/ass_fontconfig.c b/libass/ass_fontconfig.c index 2610d3d..fc258d9 100644 --- a/libass/ass_fontconfig.c +++ b/libass/ass_fontconfig.c @@ -96,7 +96,8 @@ static void scan_fonts(FcConfig *config, ASS_FontProvider *provider) for (i = 0; i < fonts->nfont; i++) { FcPattern *pat = fonts->fonts[i]; FcBool outline; - int index, weight; + int index; + double weight; char *path; char *fullnames[MAX_NAME]; char *families[MAX_NAME]; @@ -109,23 +110,26 @@ static void scan_fonts(FcConfig *config, ASS_FontProvider *provider) // simple types result = FcPatternGetInteger(pat, FC_SLANT, 0, &meta.slant); result |= FcPatternGetInteger(pat, FC_WIDTH, 0, &meta.width); - result |= FcPatternGetInteger(pat, FC_WEIGHT, 0, &weight); + result |= FcPatternGetDouble(pat, FC_WEIGHT, 0, &weight); result |= FcPatternGetInteger(pat, FC_INDEX, 0, &index); if (result != FcResultMatch) continue; // fontconfig uses its own weight scale, apparently derived // from typographical weight. we're using truetype weights, so - // convert appropriately -#if FC_VERSION >= 21191 - meta.weight = FcWeightToOpenType(weight); + // convert appropriately. +#if FC_VERSION >= 21292 + meta.weight = FcWeightToOpenTypeDouble(weight) + 0.5; +#elif FC_VERSION >= 21191 + // Versions prior to 2.12.92 only had integer precision. + meta.weight = FcWeightToOpenType(weight + 0.5) + 0.5; #else // On older fontconfig, FcWeightToOpenType is unavailable, and its inverse was // implemented more simply, using an if/else ladder instead of linear interpolation. // We implement an inverse of that ladder here. // We don't expect actual FC caches from these versions to have intermediate // values, so the average checks are only for completeness. -#define AVG(x, y) ((x + y) / 2) +#define AVG(x, y) (((double)x + y) / 2) #ifndef FC_WEIGHT_SEMILIGHT #define FC_WEIGHT_SEMILIGHT 55 #endif -- cgit v1.2.3