diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2018-01-03 15:59:24 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2018-01-03 15:59:56 +0000 |
commit | 706535e10715938c10e65e727feb607373ac1a47 (patch) | |
tree | 2d3088f450895058a8211f51bca24b0b4c59f772 /src | |
parent | 97898b1158542d3bc5f8a95fe2aa1829512cceb8 (diff) |
Add FcWeightTo/FromOpenTypeDouble()
No idea why I didn't add these as double to begin with.
Diffstat (limited to 'src')
-rw-r--r-- | src/fcfreetype.c | 16 | ||||
-rw-r--r-- | src/fcweight.c | 24 |
2 files changed, 26 insertions, 14 deletions
diff --git a/src/fcfreetype.c b/src/fcfreetype.c index 23138a90..da2dc3f3 100644 --- a/src/fcfreetype.c +++ b/src/fcfreetype.c @@ -1171,7 +1171,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face face, { FcPattern *pat; int slant = -1; - int weight = -1; + double weight = -1; int width = -1; FcBool decorative = FcFalse; FcBool variable = FcFalse; @@ -1264,8 +1264,8 @@ FcFreeTypeQueryFaceInternal (const FT_Face face, { case FT_MAKE_TAG ('w','g','h','t'): elt = FC_WEIGHT; - min_value = FcWeightFromOpenType (min_value); - max_value = FcWeightFromOpenType (max_value); + min_value = FcWeightFromOpenTypeDouble (min_value); + max_value = FcWeightFromOpenTypeDouble (max_value); variable_weight = FcTrue; weight = 0; /* To stop looking for weight. */ break; @@ -1694,15 +1694,15 @@ FcFreeTypeQueryFaceInternal (const FT_Face face, { /* Work around bad values by cleaning them up before * multiplying by weight_mult. */ - weight = FcWeightToOpenType (FcWeightFromOpenType (weight)); + weight = FcWeightToOpenTypeDouble (FcWeightFromOpenTypeDouble (weight)); } - weight = FcWeightFromOpenType ((int) (weight * weight_mult + .5)); + weight = FcWeightFromOpenTypeDouble ((int) (weight * weight_mult + .5)); if ((FcDebug() & FC_DBG_SCANV) && weight != -1) - printf ("\tos2 weight class %d multiplier %g maps to weight %d\n", + printf ("\tos2 weight class %d multiplier %g maps to weight %g\n", os2->usWeightClass, weight_mult, weight); /* TODO: - * Add FcWidthFromOpenType and FcWidthToOpenType, + * Add FcWidthFromOpenTypeDouble and FcWidthToOpenTypeDouble, * and apply width_mult post-conversion? */ switch ((int) (os2->usWidthClass * width_mult + .5)) { case 1: width = FC_WIDTH_ULTRACONDENSED; break; @@ -1893,7 +1893,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face face, if (!FcPatternAddInteger (pat, FC_SLANT, slant)) goto bail1; - if (!variable_weight && !FcPatternAddInteger (pat, FC_WEIGHT, weight)) + if (!variable_weight && !FcPatternAddDouble (pat, FC_WEIGHT, weight)) goto bail1; if (!variable_width && !FcPatternAddInteger (pat, FC_WIDTH, width)) diff --git a/src/fcweight.c b/src/fcweight.c index 67103c4a..278231dd 100644 --- a/src/fcweight.c +++ b/src/fcweight.c @@ -41,7 +41,7 @@ static const struct { {1000, FC_WEIGHT_EXTRABLACK }, }; -static int lerp(int x, int x1, int x2, int y1, int y2) +static double lerp(double x, int x1, int x2, int y1, int y2) { int dx = x2 - x1; int dy = y2 - y1; @@ -49,8 +49,8 @@ static int lerp(int x, int x1, int x2, int y1, int y2) return y1 + (dy*(x-x1) + dx/2) / dx; } -int -FcWeightFromOpenType (int ot_weight) +double +FcWeightFromOpenTypeDouble (double ot_weight) { int i; @@ -63,7 +63,7 @@ FcWeightFromOpenType (int ot_weight) /* WPF Font Selection Model says do "ot_weight *= 100", * but Greg Hitchcock revealed that GDI had a mapping * reflected below: */ - switch (ot_weight) { + switch ((int) ot_weight) { case 1: ot_weight = 80; break; case 2: ot_weight = 160; break; case 3: ot_weight = 240; break; @@ -87,8 +87,8 @@ FcWeightFromOpenType (int ot_weight) return lerp (ot_weight, map[i-1].ot, map[i].ot, map[i-1].fc, map[i].fc); } -int -FcWeightToOpenType (int fc_weight) +double +FcWeightToOpenTypeDouble (double fc_weight) { int i; if (fc_weight < 0 || fc_weight > FC_WEIGHT_EXTRABLACK) @@ -104,6 +104,18 @@ FcWeightToOpenType (int fc_weight) return lerp (fc_weight, map[i-1].fc, map[i].fc, map[i-1].ot, map[i].ot); } +int +FcWeightFromOpenType (int ot_weight) +{ + return FcWeightFromOpenTypeDouble (ot_weight) + .5; +} + +int +FcWeightToOpenType (int fc_weight) +{ + return FcWeightToOpenTypeDouble (fc_weight) + .5; +} + #define __fcweight__ #include "fcaliastail.h" #undef __fcweight__ |