4 * Copyright © 2000 Tuomas J. Lukka
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.
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.
31 FcMatrix _id = { 1, 0, 0, 1 };
32 const FcMatrixPtr FcIdentityMatrix = {
33 .storage = FcStorageDynamic,
38 FcMatrixCopy (const FcMatrix *mat)
43 r = (FcMatrix *) malloc (sizeof (*r) );
46 FcMemAlloc (FC_MEM_MATRIX, sizeof (FcMatrix));
52 FcMatrixPtrDestroy (FcMatrixPtr mi)
54 if (mi.storage == FcStorageDynamic)
55 FcMatrixFree (mi.u.dyn);
59 FcMatrixFree (FcMatrix *mat)
61 if (mat != FcMatrixPtrU(FcIdentityMatrix))
63 FcMemFree (FC_MEM_MATRIX, sizeof (FcMatrix));
69 FcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2)
71 if(mat1 == mat2) return FcTrue;
72 if(mat1 == 0 || mat2 == 0) return FcFalse;
73 return mat1->xx == mat2->xx &&
74 mat1->xy == mat2->xy &&
75 mat1->yx == mat2->yx &&
80 FcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b)
84 r.xx = a->xx * b->xx + a->xy * b->yx;
85 r.xy = a->xx * b->xy + a->xy * b->yy;
86 r.yx = a->yx * b->xx + a->yy * b->yx;
87 r.yy = a->yx * b->xy + a->yy * b->yy;
92 FcMatrixRotate (FcMatrix *m, double c, double s)
97 * X Coordinate system is upside down, swap to make
98 * rotations counterclockwise
104 FcMatrixMultiply (m, &r, m);
108 FcMatrixScale (FcMatrix *m, double sx, double sy)
116 FcMatrixMultiply (m, &r, m);
120 FcMatrixShear (FcMatrix *m, double sh, double sv)
128 FcMatrixMultiply (m, &r, m);
131 static FcMatrix * matrices = 0;
132 static int matrix_ptr = 0, matrix_count = 0;
135 FcMatrixClearStatic (void)
143 FcMatrixPtrU (FcMatrixPtr mi)
147 case FcStorageDynamic:
149 case FcStorageStatic:
150 return &matrices[mi.u.stat];
158 FcMatrixPtrCreateDynamic (FcMatrix *mi)
161 new.storage = FcStorageDynamic;
167 FcMatrixPrepareSerialize(FcMatrix *m)
174 FcMatrixSerialize(FcMatrix *m)
178 if (matrix_count == matrix_ptr)
179 return FcMatrixPtrCreateDynamic(0);
181 new.storage = FcStorageStatic;
182 new.u.stat = matrix_ptr++;
187 FcMatrixRead (int fd, FcCache metadata)
189 matrices = mmap(NULL,
190 metadata.matrices_length * sizeof (FcMatrix),
192 MAP_SHARED, fd, metadata.matrices_offset);
193 if (matrices == MAP_FAILED)
196 matrix_count = matrix_ptr = metadata.matrices_length;
201 FcMatrixWrite (int fd, FcCache *metadata)
203 metadata->matrices_length = matrix_ptr;
204 metadata->matrices_offset = FcCacheNextOffset(fd);
208 lseek(fd, metadata->matrices_offset, SEEK_SET);
209 return write(fd, matrices,
210 metadata->matrices_length * sizeof(FcMatrix)) != -1;