10 struct glyph gl
[NGLYPHS
]; /* font glyphs */
11 int gl_n
; /* number of glyphs in gl[] */
12 /* charset mapping; ch[i] is mapped to glyph ch_g[i] */
13 char ch
[NGLYPHS
][GNLEN
];
15 int ch_n
; /* number of characters in ch[] */
16 /* glyph table; lists per glyph identifier starting character */
17 int ghead
[256]; /* glyph list head */
18 int gnext
[NGLYPHS
]; /* next item in glyph list */
19 /* charset table; lists per mapping starting character */
20 int chead
[256]; /* charset list head */
21 int cnext
[NGLYPHS
]; /* next item in glyph list */
24 struct glyph
*font_find(struct font
*fn
, char *name
)
26 int i
= fn
->chead
[(unsigned char) name
[0]];
28 if (!strcmp(name
, fn
->ch
[i
]))
29 return fn
->gl
+ fn
->ch_g
[i
];
35 struct glyph
*font_glyph(struct font
*fn
, char *id
)
37 int i
= fn
->ghead
[(unsigned char) id
[0]];
39 if (!strcmp(fn
->gl
[i
].id
, id
))
46 static struct glyph
*font_glyphput(struct font
*fn
, char *id
,
47 char *name
, int wid
, int type
)
53 strcpy(g
->name
, name
);
57 fn
->gnext
[i
] = fn
->ghead
[(unsigned char) id
[0]];
58 fn
->ghead
[(unsigned char) id
[0]] = i
;
62 static void tilloel(FILE *fin
, char *s
)
65 while (c
!= EOF
&& c
!= '\n') {
74 static int font_readchar(struct font
*fn
, FILE *fin
)
79 struct glyph
*glyph
= NULL
;
81 if (fn
->ch_n
>= NGLYPHS
)
83 if (fscanf(fin
, "%s %s", name
, tok
) != 2)
85 if (!strcmp("---", name
))
86 sprintf(name
, "c%04d", fn
->ch_n
);
87 if (strcmp("\"", tok
)) {
89 if (fscanf(fin
, "%d %s", &type
, id
) != 2)
91 glyph
= font_glyph(fn
, id
);
93 glyph
= font_glyphput(fn
, id
, name
, wid
, type
);
95 if (sscanf(tok
, "%d", &glyph
->pos
) < 1)
99 glyph
= fn
->gl
+ fn
->ch_g
[fn
->ch_n
- 1];
101 strcpy(fn
->ch
[fn
->ch_n
], name
);
102 fn
->ch_g
[fn
->ch_n
] = glyph
- fn
->gl
;
103 fn
->cnext
[fn
->ch_n
] = fn
->chead
[(unsigned char) name
[0]];
104 fn
->chead
[(unsigned char) name
[0]] = fn
->ch_n
;
109 static void skipline(FILE* filp
)
114 } while (c
!= '\n' && c
!= EOF
);
117 struct font
*font_open(char *path
)
123 fin
= fopen(path
, "r");
126 fn
= malloc(sizeof(*fn
));
131 memset(fn
, 0, sizeof(*fn
));
132 for (i
= 0; i
< LEN(fn
->ghead
); i
++)
134 for (i
= 0; i
< LEN(fn
->chead
); i
++)
136 while (fscanf(fin
, "%s", tok
) == 1) {
137 if (!strcmp("char", tok
)) {
138 font_readchar(fn
, fin
);
139 } else if (!strcmp("spacewidth", tok
)) {
140 fscanf(fin
, "%d", &fn
->spacewid
);
141 } else if (!strcmp("name", tok
)) {
142 fscanf(fin
, "%s", fn
->name
);
143 } else if (!strcmp("fontname", tok
)) {
144 fscanf(fin
, "%s", fn
->fontname
);
145 } else if (!strcmp("ligatures", tok
)) {
146 while (fscanf(fin
, "%s", tok
) == 1)
147 if (!strcmp("0", tok
))
149 } else if (!strcmp("charset", tok
)) {
150 while (!font_readchar(fn
, fin
))
160 void font_close(struct font
*fn
)
165 int font_wid(struct font
*fn
, int sz
, int w
)
167 return (w
* sz
+ dev_uwid
/ 2) / dev_uwid
;
170 int font_swid(struct font
*fn
, int sz
)
172 return font_wid(fn
, sz
, fn
->spacewid
);
175 char *font_name(struct font
*fn
)