summaryrefslogtreecommitdiffstats
path: root/libass
diff options
context:
space:
mode:
authorrcombs <rcombs@rcombs.me>2020-09-16 23:36:20 -0500
committerOleg Oshmyan <chortos@inbox.lv>2020-09-19 17:49:41 +0300
commit6bb17b7e7b783844e66335a7293c82c93ea757d3 (patch)
treee3ab2e1ebdd82e416b1d17e38aae513ebd7730e0 /libass
parent7cc111d16586716781e0265b3b96cd6768883cec (diff)
downloadlibass-6bb17b7e7b783844e66335a7293c82c93ea757d3.tar.bz2
libass-6bb17b7e7b783844e66335a7293c82c93ea757d3.tar.xz
ass_fontconfig: use FcWeightToOpenTypeDouble
This provides higher precision in reported weights when using the fontconfig font provider.
Diffstat (limited to 'libass')
-rw-r--r--libass/ass_fontconfig.c16
1 files changed, 10 insertions, 6 deletions
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