-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfc.c
More file actions
118 lines (107 loc) · 1.93 KB
/
Copy pathfc.c
File metadata and controls
118 lines (107 loc) · 1.93 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// FontConfig-like API implementation
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <draw.h>
#include <memdraw.h>
#include "dat.h"
static FcFontSet*
allocfontset(void)
{
return emalloc9p(sizeof(FcPattern));
};
static FcPattern*
allocpat(void)
{
return emalloc9p(sizeof(FcPattern));
};
int
FcInit(void)
{
return 1;
};
FcConfig*
FcInitLoadConfigAndFonts(void)
{
return emalloc9p(sizeof(FcConfig));
};
static void
appendfontset(FcFontSet* fset, FcPattern* pat)
{
int n;
n = fset->nfont;
fset->fonts = realloc(fset->fonts, (n+1)*sizeof(FcPattern*));
fset->fonts[n++] = pat;
fset->nfont = n;
};
void
FcFontSetDestroy(FcFontSet* fset)
{
int i;
for(i = 0; i < fset->nfont; i++)
free(fset->fonts[i]);
free(fset);
};
FcFontSet*
FcConfigGetFonts(FcConfig*, int)
{
FcFontSet* fset;
FcPattern* d;
Biobuf *b;
char *s, *pr, *file, *line, *f[3];
int ntok;
fset = allocfontset();
file = "/sys/lib/fontsrv.map";
b = Bopen(file, OREAD);
while((line = Brdline(b, '\n')) != nil){
line[Blinelen(b)-1] = 0;
s = strchr(line, '#');
if(s != nil && (s == line || s[-1] == ' ' || s[-1] == '\t'))
*s = '\0'; /* chop comment iff after whitespace */
ntok = tokenize(line, f, nelem(f));
switch(ntok){
case 1:
d = allocpat();
d->fontfile = strdup(f[0]);
pr = utfrrune(f[0], '/');
if(pr)
pr++;
else
pr = f[0];
d->name = strdup(pr);
appendfontset(fset, d);
break;
case 2:
d = allocpat();
d->name = strdup(f[0]);
d->fontfile = strdup(f[1]);
appendfontset(fset, d);
break;
}
}
Bterm(b);
return fset;
};
int
FcPatternGetString(FcPattern* pat, int attr, int, FcChar8** res)
{
switch(attr){
case FC_POSTSCRIPT_NAME:
*res = pat->name;
return FcResultMatch;
case FC_FILE:
*res = pat->fontfile;
return FcResultMatch;
}
return -1;
}
int
FcPatternGetInteger(FcPattern* pat, int attr, int, int* res)
{
switch(attr){
case FC_INDEX:
*res = pat->index;
return FcResultMatch;
}
return -1;
}