Coverage Report

Created: 2025-07-07 10:01

/work/workdir/UnpackedTarball/fontconfig/src/fcmatrix.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * fontconfig/src/fcmatrix.c
3
 *
4
 * Copyright © 2000 Tuomas J. Lukka
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
25
#include "fcint.h"
26
27
#include <ctype.h>
28
#include <math.h>
29
#include <stdlib.h>
30
31
const FcMatrix FcIdentityMatrix = { 1, 0, 0, 1 };
32
33
FcMatrix *
34
FcMatrixCopy (const FcMatrix *mat)
35
0
{
36
0
    FcMatrix *r;
37
0
    if (!mat)
38
0
  return 0;
39
0
    r = (FcMatrix *)malloc (sizeof (*r));
40
0
    if (!r)
41
0
  return 0;
42
0
    *r = *mat;
43
0
    return r;
44
0
}
45
46
void
47
FcMatrixFree (FcMatrix *mat)
48
0
{
49
0
    if (mat != &FcIdentityMatrix)
50
0
  free (mat);
51
0
}
52
53
FcBool
54
FcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2)
55
0
{
56
0
    if (mat1 == mat2)
57
0
  return FcTrue;
58
0
    if (mat1 == 0 || mat2 == 0)
59
0
  return FcFalse;
60
0
    return mat1->xx == mat2->xx &&
61
0
           mat1->xy == mat2->xy &&
62
0
           mat1->yx == mat2->yx &&
63
0
           mat1->yy == mat2->yy;
64
0
}
65
66
void
67
FcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b)
68
0
{
69
0
    FcMatrix r;
70
71
0
    r.xx = a->xx * b->xx + a->xy * b->yx;
72
0
    r.xy = a->xx * b->xy + a->xy * b->yy;
73
0
    r.yx = a->yx * b->xx + a->yy * b->yx;
74
0
    r.yy = a->yx * b->xy + a->yy * b->yy;
75
0
    *result = r;
76
0
}
77
78
void
79
FcMatrixRotate (FcMatrix *m, double c, double s)
80
0
{
81
0
    FcMatrix r;
82
83
    /*
84
     * X Coordinate system is upside down, swap to make
85
     * rotations counterclockwise
86
     */
87
0
    r.xx = c;
88
0
    r.xy = -s;
89
0
    r.yx = s;
90
0
    r.yy = c;
91
0
    FcMatrixMultiply (m, &r, m);
92
0
}
93
94
void
95
FcMatrixScale (FcMatrix *m, double sx, double sy)
96
0
{
97
0
    FcMatrix r;
98
99
0
    r.xx = sx;
100
0
    r.xy = 0;
101
0
    r.yx = 0;
102
0
    r.yy = sy;
103
0
    FcMatrixMultiply (m, &r, m);
104
0
}
105
106
void
107
FcMatrixShear (FcMatrix *m, double sh, double sv)
108
0
{
109
0
    FcMatrix r;
110
111
0
    r.xx = 1;
112
0
    r.xy = sh;
113
0
    r.yx = sv;
114
0
    r.yy = 1;
115
0
    FcMatrixMultiply (m, &r, m);
116
0
}
117
#define __fcmatrix__
118
#include "fcaliastail.h"
119
#undef __fcmatrix__