diff options
author | marha <marha@users.sourceforge.net> | 2014-07-28 21:19:00 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2014-07-28 21:19:00 +0200 |
commit | b33b8d8ae86876b50df96881b96074b3fe177cce (patch) | |
tree | bcdfa896ef05643b7edc1cd06518cbb7fed72c72 /fontconfig/src/fcweight.c | |
parent | d0c30e7945e76ac119f6d867e27137c8a76f7e15 (diff) | |
download | vcxsrv-b33b8d8ae86876b50df96881b96074b3fe177cce.tar.gz vcxsrv-b33b8d8ae86876b50df96881b96074b3fe177cce.tar.bz2 vcxsrv-b33b8d8ae86876b50df96881b96074b3fe177cce.zip |
plink fontconfig libX11 libXext xserver xkeyboard-config mesa git update 28 July 2014
xserver commit 4afedf545b673282f2e214c0e2c759c9be9b9a2a
xkeyboard-config commit 9010f6c0745f472b670c22340b5bbd36e33ce37e
libX11 commit 0885cad1e4a9ed57266582be320be55259c881bf
libXext commit efdcbb7634501e1117d422636a0a75d7ea84b16b
fontconfig commit a9e7b0494e04b3925d1bccc140ff2500cfff9618
mesa commit cc1e1da24a6c535617d9fb38858d48d8c2999e68
plink revision 10211
Diffstat (limited to 'fontconfig/src/fcweight.c')
-rw-r--r-- | fontconfig/src/fcweight.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/fontconfig/src/fcweight.c b/fontconfig/src/fcweight.c new file mode 100644 index 000000000..87bbe67ab --- /dev/null +++ b/fontconfig/src/fcweight.c @@ -0,0 +1,88 @@ +/* + * fontconfig/src/fcweight.c + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" + +static const struct { + int ot; + int fc; +} map[] = { + { 0, FC_WEIGHT_THIN }, + { 100, FC_WEIGHT_THIN }, + { 200, FC_WEIGHT_EXTRALIGHT }, + { 350, FC_WEIGHT_DEMILIGHT }, + { 300, FC_WEIGHT_LIGHT }, + { 380, FC_WEIGHT_BOOK }, + { 400, FC_WEIGHT_REGULAR }, + { 500, FC_WEIGHT_MEDIUM }, + { 600, FC_WEIGHT_DEMIBOLD }, + { 700, FC_WEIGHT_BOLD }, + { 800, FC_WEIGHT_EXTRABOLD }, + { 900, FC_WEIGHT_BLACK }, + {1000, FC_WEIGHT_EXTRABLACK }, +}; + +static int lerp(int x, int x1, int x2, int y1, int y2) +{ + int dx = x2 - x1; + int dy = y2 - y1; + assert (dx > 0 && dy > 0 && x1 <= x && x <= x2); + return y1 + (dy*(x-x1) + dx/2) / dx; +} + +FcPublic int +FcWeightFromOpenType (int ot_weight) +{ + int i; + if (ot_weight <= 0 || ot_weight > 1000) + return -1; + + for (i = 1; ot_weight > map[i].ot; i++) + ; + + if (ot_weight == map[i].ot) + return map[i].fc; + + /* Interpolate between two items. */ + return lerp (ot_weight, map[i-1].ot, map[i].ot, map[i-1].fc, map[i].fc); +} + +FcPublic int +FcWeightToOpenType (int fc_weight) +{ + int i; + if (fc_weight < 0 || fc_weight > FC_WEIGHT_EXTRABLACK) + return -1; + + for (i = 1; fc_weight > map[i].fc; i++) + ; + + if (fc_weight == map[i].fc) + return map[i].ot; + + /* Interpolate between two items. */ + return lerp (fc_weight, map[i-1].fc, map[i].fc, map[i-1].ot, map[i].ot); +} + +#define __fcweight__ +#include "fcaliastail.h" +#undef __fcweight__ |