fcmatrix.c revision ca08ab68
12c393a42Smrg/* 2a6844aabSmrg * fontconfig/src/fcmatrix.c 32c393a42Smrg * 42c393a42Smrg * Copyright © 2000 Tuomas J. Lukka 52c393a42Smrg * 62c393a42Smrg * Permission to use, copy, modify, distribute, and sell this software and its 72c393a42Smrg * documentation for any purpose is hereby granted without fee, provided that 82c393a42Smrg * the above copyright notice appear in all copies and that both that 92c393a42Smrg * copyright notice and this permission notice appear in supporting 102c393a42Smrg * documentation, and that the name of Tuomas Lukka not be used in 112c393a42Smrg * advertising or publicity pertaining to distribution of the software without 122c393a42Smrg * specific, written prior permission. Tuomas Lukka makes no 132c393a42Smrg * representations about the suitability of this software for any purpose. It 142c393a42Smrg * is provided "as is" without express or implied warranty. 152c393a42Smrg * 162c393a42Smrg * TUOMAS LUKKA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 172c393a42Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 182c393a42Smrg * EVENT SHALL TUOMAS LUKKA BE LIABLE FOR ANY SPECIAL, INDIRECT OR 192c393a42Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 202c393a42Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 212c393a42Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 222c393a42Smrg * PERFORMANCE OF THIS SOFTWARE. 232c393a42Smrg */ 242c393a42Smrg 252c393a42Smrg#include "fcint.h" 262c393a42Smrg#include <math.h> 272c393a42Smrg#include <stdlib.h> 282c393a42Smrg#include <ctype.h> 292c393a42Smrg 302c393a42Smrgconst FcMatrix FcIdentityMatrix = { 1, 0, 0, 1 }; 312c393a42Smrg 322c393a42SmrgFcMatrix * 33ca08ab68SmrgFcMatrixCopy (const FcMatrix *mat) 342c393a42Smrg{ 352c393a42Smrg FcMatrix *r; 36ca08ab68Smrg if(!mat) 372c393a42Smrg return 0; 382c393a42Smrg r = (FcMatrix *) malloc (sizeof (*r) ); 392c393a42Smrg if (!r) 402c393a42Smrg return 0; 412c393a42Smrg FcMemAlloc (FC_MEM_MATRIX, sizeof (FcMatrix)); 422c393a42Smrg *r = *mat; 432c393a42Smrg return r; 442c393a42Smrg} 452c393a42Smrg 462c393a42Smrgvoid 472c393a42SmrgFcMatrixFree (FcMatrix *mat) 482c393a42Smrg{ 492c393a42Smrg if (mat != &FcIdentityMatrix) 502c393a42Smrg { 512c393a42Smrg FcMemFree (FC_MEM_MATRIX, sizeof (FcMatrix)); 522c393a42Smrg free (mat); 532c393a42Smrg } 542c393a42Smrg} 552c393a42Smrg 562c393a42SmrgFcBool 572c393a42SmrgFcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2) 582c393a42Smrg{ 592c393a42Smrg if(mat1 == mat2) return FcTrue; 602c393a42Smrg if(mat1 == 0 || mat2 == 0) return FcFalse; 61ca08ab68Smrg return mat1->xx == mat2->xx && 622c393a42Smrg mat1->xy == mat2->xy && 632c393a42Smrg mat1->yx == mat2->yx && 642c393a42Smrg mat1->yy == mat2->yy; 652c393a42Smrg} 662c393a42Smrg 672c393a42Smrgvoid 682c393a42SmrgFcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b) 692c393a42Smrg{ 702c393a42Smrg FcMatrix r; 712c393a42Smrg 722c393a42Smrg r.xx = a->xx * b->xx + a->xy * b->yx; 732c393a42Smrg r.xy = a->xx * b->xy + a->xy * b->yy; 742c393a42Smrg r.yx = a->yx * b->xx + a->yy * b->yx; 752c393a42Smrg r.yy = a->yx * b->xy + a->yy * b->yy; 762c393a42Smrg *result = r; 772c393a42Smrg} 782c393a42Smrg 792c393a42Smrgvoid 802c393a42SmrgFcMatrixRotate (FcMatrix *m, double c, double s) 812c393a42Smrg{ 822c393a42Smrg FcMatrix r; 832c393a42Smrg 842c393a42Smrg /* 852c393a42Smrg * X Coordinate system is upside down, swap to make 862c393a42Smrg * rotations counterclockwise 872c393a42Smrg */ 882c393a42Smrg r.xx = c; 892c393a42Smrg r.xy = -s; 902c393a42Smrg r.yx = s; 912c393a42Smrg r.yy = c; 922c393a42Smrg FcMatrixMultiply (m, &r, m); 932c393a42Smrg} 942c393a42Smrg 952c393a42Smrgvoid 962c393a42SmrgFcMatrixScale (FcMatrix *m, double sx, double sy) 972c393a42Smrg{ 982c393a42Smrg FcMatrix r; 992c393a42Smrg 1002c393a42Smrg r.xx = sx; 1012c393a42Smrg r.xy = 0; 1022c393a42Smrg r.yx = 0; 1032c393a42Smrg r.yy = sy; 1042c393a42Smrg FcMatrixMultiply (m, &r, m); 1052c393a42Smrg} 1062c393a42Smrg 1072c393a42Smrgvoid 1082c393a42SmrgFcMatrixShear (FcMatrix *m, double sh, double sv) 1092c393a42Smrg{ 1102c393a42Smrg FcMatrix r; 1112c393a42Smrg 1122c393a42Smrg r.xx = 1; 1132c393a42Smrg r.xy = sh; 1142c393a42Smrg r.yx = sv; 1152c393a42Smrg r.yy = 1; 1162c393a42Smrg FcMatrixMultiply (m, &r, m); 1172c393a42Smrg} 1182c393a42Smrg#define __fcmatrix__ 1192c393a42Smrg#include "fcaliastail.h" 1202c393a42Smrg#undef __fcmatrix__ 121