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    *r = *mat;
422c393a42Smrg    return r;
432c393a42Smrg}
442c393a42Smrg
452c393a42Smrgvoid
462c393a42SmrgFcMatrixFree (FcMatrix *mat)
472c393a42Smrg{
482c393a42Smrg    if (mat != &FcIdentityMatrix)
492c393a42Smrg	free (mat);
502c393a42Smrg}
512c393a42Smrg
522c393a42SmrgFcBool
532c393a42SmrgFcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2)
542c393a42Smrg{
552c393a42Smrg    if(mat1 == mat2) return FcTrue;
562c393a42Smrg    if(mat1 == 0 || mat2 == 0) return FcFalse;
57ca08ab68Smrg    return mat1->xx == mat2->xx &&
582c393a42Smrg	   mat1->xy == mat2->xy &&
592c393a42Smrg	   mat1->yx == mat2->yx &&
602c393a42Smrg	   mat1->yy == mat2->yy;
612c393a42Smrg}
622c393a42Smrg
632c393a42Smrgvoid
642c393a42SmrgFcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b)
652c393a42Smrg{
662c393a42Smrg    FcMatrix	r;
672c393a42Smrg
682c393a42Smrg    r.xx = a->xx * b->xx + a->xy * b->yx;
692c393a42Smrg    r.xy = a->xx * b->xy + a->xy * b->yy;
702c393a42Smrg    r.yx = a->yx * b->xx + a->yy * b->yx;
712c393a42Smrg    r.yy = a->yx * b->xy + a->yy * b->yy;
722c393a42Smrg    *result = r;
732c393a42Smrg}
742c393a42Smrg
752c393a42Smrgvoid
762c393a42SmrgFcMatrixRotate (FcMatrix *m, double c, double s)
772c393a42Smrg{
782c393a42Smrg    FcMatrix	r;
792c393a42Smrg
802c393a42Smrg    /*
812c393a42Smrg     * X Coordinate system is upside down, swap to make
822c393a42Smrg     * rotations counterclockwise
832c393a42Smrg     */
842c393a42Smrg    r.xx = c;
852c393a42Smrg    r.xy = -s;
862c393a42Smrg    r.yx = s;
872c393a42Smrg    r.yy = c;
882c393a42Smrg    FcMatrixMultiply (m, &r, m);
892c393a42Smrg}
902c393a42Smrg
912c393a42Smrgvoid
922c393a42SmrgFcMatrixScale (FcMatrix *m, double sx, double sy)
932c393a42Smrg{
942c393a42Smrg    FcMatrix	r;
952c393a42Smrg
962c393a42Smrg    r.xx = sx;
972c393a42Smrg    r.xy = 0;
982c393a42Smrg    r.yx = 0;
992c393a42Smrg    r.yy = sy;
1002c393a42Smrg    FcMatrixMultiply (m, &r, m);
1012c393a42Smrg}
1022c393a42Smrg
1032c393a42Smrgvoid
1042c393a42SmrgFcMatrixShear (FcMatrix *m, double sh, double sv)
1052c393a42Smrg{
1062c393a42Smrg    FcMatrix	r;
1072c393a42Smrg
1082c393a42Smrg    r.xx = 1;
1092c393a42Smrg    r.xy = sh;
1102c393a42Smrg    r.yx = sv;
1112c393a42Smrg    r.yy = 1;
1122c393a42Smrg    FcMatrixMultiply (m, &r, m);
1132c393a42Smrg}
1142c393a42Smrg#define __fcmatrix__
1152c393a42Smrg#include "fcaliastail.h"
1162c393a42Smrg#undef __fcmatrix__
117