6 static void skipline(FILE* filp
)
11 } while (c
!= '\n' && c
!= EOF
);
14 struct glyph
*font_find(struct font
*fn
, char *name
)
17 for (i
= 0; i
< fn
->n
; i
++)
18 if (name
[0] == fn
->c
[i
][0] && !strcmp(name
, fn
->c
[i
]))
23 struct glyph
*font_glyph(struct font
*fn
, char *id
)
26 for (i
= 0; i
< fn
->nglyphs
; i
++)
27 if (!strcmp(fn
->glyphs
[i
].id
, id
))
28 return &fn
->glyphs
[i
];
32 static int font_section(struct font
*fn
, FILE *fin
, char *name
);
34 static void font_charset(struct font
*fn
, FILE *fin
)
39 struct glyph
*glyph
= NULL
;
40 struct glyph
*prev
= NULL
;
42 while (fscanf(fin
, "%s", name
) == 1) {
43 if (!font_section(fn
, fin
, name
))
45 if (fn
->n
>= NGLYPHS
) {
49 fscanf(fin
, "%s", tok
);
51 if (!strcmp("---", name
))
52 sprintf(name
, "c%04d", fn
->n
);
53 if (strcmp("\"", tok
)) {
55 fscanf(fin
, "%d %s", &type
, id
);
57 glyph
= &fn
->glyphs
[fn
->nglyphs
++];
58 strcpy(glyph
->id
, id
);
59 strcpy(glyph
->name
, name
);
65 strcpy(fn
->c
[fn
->n
], name
);
71 static void font_kernpairs(struct font
*fn
, FILE *fin
)
73 char c1
[ILNLEN
], c2
[ILNLEN
];
75 while (fscanf(fin
, "%s", c1
) == 1) {
76 if (!font_section(fn
, fin
, c1
))
78 if (fscanf(fin
, "%s %d", c2
, &val
) != 2)
80 if (fn
->nkern
< NKERNS
) {
81 strcpy(fn
->kern_c1
[fn
->nkern
], c1
);
82 strcpy(fn
->kern_c2
[fn
->nkern
], c2
);
83 fn
->kern
[fn
->nkern
] = val
;
89 static int font_section(struct font
*fn
, FILE *fin
, char *name
)
91 if (!strcmp("charset", name
)) {
92 font_charset(fn
, fin
);
95 if (!strcmp("kernpairs", name
)) {
96 font_kernpairs(fn
, fin
);
103 * Given a list of characters in the reverse order, font_lig()
104 * returns the number of characters from the beginning of this
105 * list that form a ligature in this font. Zero naturally means
106 * no ligature was matched.
108 int font_lig(struct font
*fn
, char **c
, int n
)
111 /* concatenated characters in c[], in the correct order */
112 char s
[GNLEN
* 2] = "";
113 /* b[i] is the number of character of c[] in s + i */
114 int b
[GNLEN
* 2] = {0};
116 for (i
= 0; i
< n
; i
++) {
117 char *cur
= c
[n
- i
- 1];
119 strcpy(s
+ len
, cur
);
122 for (i
= 0; i
< fn
->nlig
; i
++) {
123 int l
= strlen(fn
->lig
[i
]);
124 if (b
[len
- l
] && !strcmp(s
+ len
- l
, fn
->lig
[i
]))
125 if (font_find(fn
, fn
->lig
[i
]))
131 /* return pairwise kerning value between c1 and c2 */
132 int font_kern(struct font
*fn
, char *c1
, char *c2
)
135 for (i
= 0; i
< fn
->nkern
; i
++)
136 if (!strcmp(fn
->kern_c1
[i
], c1
) && !strcmp(fn
->kern_c2
[i
], c2
))
141 struct font
*font_open(char *path
)
143 struct font
*fn
= malloc(sizeof(*fn
));
146 fin
= fopen(path
, "r");
147 memset(fn
, 0, sizeof(*fn
));
148 while (fscanf(fin
, "%s", tok
) == 1) {
153 if (!strcmp("spacewidth", tok
)) {
154 fscanf(fin
, "%d", &fn
->spacewid
);
157 if (!strcmp("special", tok
)) {
161 if (!strcmp("name", tok
)) {
162 fscanf(fin
, "%s", fn
->name
);
165 if (!strcmp("fontname", tok
)) {
166 fscanf(fin
, "%s", fn
->fontname
);
169 if (!strcmp("named", tok
)) {
173 if (!strcmp("ligatures", tok
)) {
174 while (fscanf(fin
, "%s", tok
) == 1) {
175 if (!strcmp("0", tok
))
177 if (fn
->nlig
< NLIGS
)
178 strcpy(fn
->lig
[fn
->nlig
++], tok
);
183 if (!font_section(fn
, fin
, tok
))
191 void font_close(struct font
*fn
)