1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include <fontconfig/fontconfig.h>
#include <stdio.h>
static int
test (const FcChar8 *query, const FcPattern *expect)
{
FcPattern *pat;
int c = 0;
c++;
pat = FcNameParse (query);
if (!pat)
goto bail;
c++;
if (!FcPatternEqual (pat, expect))
goto bail;
c = 0;
bail:
FcPatternDestroy (pat);
return c;
}
#define BEGIN(x) (x) = FcPatternCreate (); c++;
#define END(x) FcPatternDestroy (x); (x) = NULL
int
main (void)
{
FcPattern *expect;
int c = 0, ret;
BEGIN (expect) {
FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"sans-serif");
if ((ret = test ((const FcChar8 *)"sans\\-serif", expect)) != 0)
goto bail;
} END (expect);
BEGIN (expect) {
FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"Foo");
FcPatternAddInteger (expect, FC_SIZE, 10);
if ((ret = test ((const FcChar8 *)"Foo-10", expect)) != 0)
goto bail;
} END (expect);
BEGIN (expect) {
FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"Foo");
FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"Bar");
FcPatternAddInteger (expect, FC_SIZE, 10);
if ((ret = test ((const FcChar8 *)"Foo,Bar-10", expect)) != 0)
goto bail;
} END (expect);
BEGIN (expect) {
FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"Foo");
FcPatternAddInteger (expect, FC_WEIGHT, FC_WEIGHT_MEDIUM);
if ((ret = test ((const FcChar8 *)"Foo:weight=medium", expect)) != 0)
goto bail;
} END (expect);
BEGIN (expect) {
FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"Foo");
FcPatternAddInteger (expect, FC_WEIGHT, FC_WEIGHT_MEDIUM);
if ((ret = test ((const FcChar8 *)"Foo:weight_medium", expect)) != 0)
goto bail;
} END (expect);
BEGIN (expect) {
FcPatternAddInteger (expect, FC_WEIGHT, FC_WEIGHT_MEDIUM);
if ((ret = test ((const FcChar8 *)":medium", expect)) != 0)
goto bail;
} END (expect);
BEGIN (expect) {
FcPatternAddInteger (expect, FC_WIDTH, FC_WIDTH_NORMAL);
if ((ret = test ((const FcChar8 *)":normal", expect)) != 0)
goto bail;
} END (expect);
BEGIN (expect) {
FcPatternAddInteger (expect, FC_WIDTH, FC_WIDTH_NORMAL);
if ((ret = test ((const FcChar8 *)":normal", expect)) != 0)
goto bail;
} END (expect);
BEGIN (expect) {
FcRange *r = FcRangeCreateDouble (FC_WEIGHT_MEDIUM, FC_WEIGHT_BOLD);
FcPatternAddRange (expect, FC_WEIGHT, r);
FcRangeDestroy (r);
if ((ret = test ((const FcChar8 *)":weight=[medium bold]", expect)) != 0)
goto bail;
} END (expect);
bail:
if (expect)
FcPatternDestroy (expect);
return ret == 0 ? 0 : (c - 1) * 2 + ret;
}
|