]> git.wh0rd.org - fontconfig.git/blame - src/fcmatrix.c
Bug 44826 - <alias> must contain only a single <family>
[fontconfig.git] / src / fcmatrix.c
CommitLineData
24330d27 1/*
317b8492 2 * fontconfig/src/fcmatrix.c
24330d27 3 *
46b51147 4 * Copyright © 2000 Tuomas J. Lukka
24330d27
KP
5 *
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Tuomas Lukka not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Tuomas Lukka makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
15 *
16 * TUOMAS LUKKA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL TUOMAS LUKKA BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
23 */
24
f045376c 25#include "fcint.h"
24330d27
KP
26#include <math.h>
27#include <stdlib.h>
28#include <ctype.h>
24330d27 29
4262e0b3 30const FcMatrix FcIdentityMatrix = { 1, 0, 0, 1 };
327a7fd4 31
24330d27 32FcMatrix *
594dcef0 33FcMatrixCopy (const FcMatrix *mat)
24330d27
KP
34{
35 FcMatrix *r;
594dcef0 36 if(!mat)
24330d27
KP
37 return 0;
38 r = (FcMatrix *) malloc (sizeof (*r) );
39 if (!r)
40 return 0;
41 FcMemAlloc (FC_MEM_MATRIX, sizeof (FcMatrix));
42 *r = *mat;
43 return r;
44}
45
46void
47FcMatrixFree (FcMatrix *mat)
48{
4262e0b3 49 if (mat != &FcIdentityMatrix)
327a7fd4
KP
50 {
51 FcMemFree (FC_MEM_MATRIX, sizeof (FcMatrix));
52 free (mat);
53 }
24330d27
KP
54}
55
56FcBool
57FcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2)
58{
59 if(mat1 == mat2) return FcTrue;
60 if(mat1 == 0 || mat2 == 0) return FcFalse;
594dcef0 61 return mat1->xx == mat2->xx &&
24330d27
KP
62 mat1->xy == mat2->xy &&
63 mat1->yx == mat2->yx &&
64 mat1->yy == mat2->yy;
65}
66
67void
68FcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b)
69{
70 FcMatrix r;
71
72 r.xx = a->xx * b->xx + a->xy * b->yx;
73 r.xy = a->xx * b->xy + a->xy * b->yy;
74 r.yx = a->yx * b->xx + a->yy * b->yx;
75 r.yy = a->yx * b->xy + a->yy * b->yy;
76 *result = r;
77}
78
79void
80FcMatrixRotate (FcMatrix *m, double c, double s)
81{
82 FcMatrix r;
83
84 /*
85 * X Coordinate system is upside down, swap to make
86 * rotations counterclockwise
87 */
88 r.xx = c;
89 r.xy = -s;
90 r.yx = s;
91 r.yy = c;
92 FcMatrixMultiply (m, &r, m);
93}
94
95void
96FcMatrixScale (FcMatrix *m, double sx, double sy)
97{
98 FcMatrix r;
99
100 r.xx = sx;
101 r.xy = 0;
102 r.yx = 0;
103 r.yy = sy;
104 FcMatrixMultiply (m, &r, m);
105}
106
107void
108FcMatrixShear (FcMatrix *m, double sh, double sv)
109{
110 FcMatrix r;
111
112 r.xx = 1;
113 r.xy = sh;
114 r.yx = sv;
115 r.yy = 1;
116 FcMatrixMultiply (m, &r, m);
117}
23816bf9
KP
118#define __fcmatrix__
119#include "fcaliastail.h"
120#undef __fcmatrix__