|
Packit |
352660 |
/*
|
|
Packit |
352660 |
* fontconfig/src/fcweight.c
|
|
Packit |
352660 |
*
|
|
Packit |
352660 |
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
Packit |
352660 |
* documentation for any purpose is hereby granted without fee, provided that
|
|
Packit |
352660 |
* the above copyright notice appear in all copies and that both that
|
|
Packit |
352660 |
* copyright notice and this permission notice appear in supporting
|
|
Packit |
352660 |
* documentation, and that the name of the author(s) not be used in
|
|
Packit |
352660 |
* advertising or publicity pertaining to distribution of the software without
|
|
Packit |
352660 |
* specific, written prior permission. The authors make no
|
|
Packit |
352660 |
* representations about the suitability of this software for any purpose. It
|
|
Packit |
352660 |
* is provided "as is" without express or implied warranty.
|
|
Packit |
352660 |
*
|
|
Packit |
352660 |
* THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
Packit |
352660 |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
Packit |
352660 |
* EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
Packit |
352660 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
Packit |
352660 |
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
Packit |
352660 |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
Packit |
352660 |
* PERFORMANCE OF THIS SOFTWARE.
|
|
Packit |
352660 |
*/
|
|
Packit |
352660 |
|
|
Packit |
352660 |
#include "fcint.h"
|
|
Packit |
352660 |
|
|
Packit |
352660 |
static const struct {
|
|
Packit |
352660 |
int ot;
|
|
Packit |
352660 |
int fc;
|
|
Packit |
352660 |
} map[] = {
|
|
Packit |
352660 |
{ 0, FC_WEIGHT_THIN },
|
|
Packit |
352660 |
{ 100, FC_WEIGHT_THIN },
|
|
Packit |
352660 |
{ 200, FC_WEIGHT_EXTRALIGHT },
|
|
Packit |
352660 |
{ 300, FC_WEIGHT_LIGHT },
|
|
Packit |
352660 |
{ 350, FC_WEIGHT_DEMILIGHT },
|
|
Packit |
352660 |
{ 380, FC_WEIGHT_BOOK },
|
|
Packit |
352660 |
{ 400, FC_WEIGHT_REGULAR },
|
|
Packit |
352660 |
{ 500, FC_WEIGHT_MEDIUM },
|
|
Packit |
352660 |
{ 600, FC_WEIGHT_DEMIBOLD },
|
|
Packit |
352660 |
{ 700, FC_WEIGHT_BOLD },
|
|
Packit |
352660 |
{ 800, FC_WEIGHT_EXTRABOLD },
|
|
Packit |
352660 |
{ 900, FC_WEIGHT_BLACK },
|
|
Packit |
352660 |
{1000, FC_WEIGHT_EXTRABLACK },
|
|
Packit |
352660 |
};
|
|
Packit |
352660 |
|
|
Packit |
352660 |
static double lerp(double x, int x1, int x2, int y1, int y2)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
int dx = x2 - x1;
|
|
Packit |
352660 |
int dy = y2 - y1;
|
|
Packit |
352660 |
assert (dx > 0 && dy >= 0 && x1 <= x && x <= x2);
|
|
Packit |
352660 |
return y1 + (dy*(x-x1) + dx/2) / dx;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
|
|
Packit |
352660 |
double
|
|
Packit |
352660 |
FcWeightFromOpenTypeDouble (double ot_weight)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
int i;
|
|
Packit |
352660 |
|
|
Packit |
352660 |
if (ot_weight < 0)
|
|
Packit |
352660 |
return -1;
|
|
Packit |
352660 |
|
|
Packit |
352660 |
ot_weight = FC_MIN (ot_weight, map[(sizeof (map) / sizeof (map[0])) - 1].ot);
|
|
Packit |
352660 |
|
|
Packit |
352660 |
for (i = 1; ot_weight > map[i].ot; i++)
|
|
Packit |
352660 |
;
|
|
Packit |
352660 |
|
|
Packit |
352660 |
if (ot_weight == map[i].ot)
|
|
Packit |
352660 |
return map[i].fc;
|
|
Packit |
352660 |
|
|
Packit |
352660 |
/* Interpolate between two items. */
|
|
Packit |
352660 |
return lerp (ot_weight, map[i-1].ot, map[i].ot, map[i-1].fc, map[i].fc);
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
|
|
Packit |
352660 |
double
|
|
Packit |
352660 |
FcWeightToOpenTypeDouble (double fc_weight)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
int i;
|
|
Packit |
352660 |
if (fc_weight < 0 || fc_weight > FC_WEIGHT_EXTRABLACK)
|
|
Packit |
352660 |
return -1;
|
|
Packit |
352660 |
|
|
Packit |
352660 |
for (i = 1; fc_weight > map[i].fc; i++)
|
|
Packit |
352660 |
;
|
|
Packit |
352660 |
|
|
Packit |
352660 |
if (fc_weight == map[i].fc)
|
|
Packit |
352660 |
return map[i].ot;
|
|
Packit |
352660 |
|
|
Packit |
352660 |
/* Interpolate between two items. */
|
|
Packit |
352660 |
return lerp (fc_weight, map[i-1].fc, map[i].fc, map[i-1].ot, map[i].ot);
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
|
|
Packit |
352660 |
int
|
|
Packit |
352660 |
FcWeightFromOpenType (int ot_weight)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
return FcWeightFromOpenTypeDouble (ot_weight) + .5;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
|
|
Packit |
352660 |
int
|
|
Packit |
352660 |
FcWeightToOpenType (int fc_weight)
|
|
Packit |
352660 |
{
|
|
Packit |
352660 |
return FcWeightToOpenTypeDouble (fc_weight) + .5;
|
|
Packit |
352660 |
}
|
|
Packit |
352660 |
|
|
Packit |
352660 |
#define __fcweight__
|
|
Packit |
352660 |
#include "fcaliastail.h"
|
|
Packit |
352660 |
#undef __fcweight__
|