summaryrefslogtreecommitdiff
path: root/src/fcweight.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fcweight.c')
-rw-r--r--src/fcweight.c24
1 files changed, 18 insertions, 6 deletions
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__