ref: 3d33563e7a7a4d0772f70260cbedb89d5f175ab2
parent: 61fc64623183c2b3d79be27c857c6e44d8e6fc8d
author: Ali Gholami Rudi <ali@rudi.ir>
date: Thu Apr 13 11:59:06 EDT 2017
font: search character aliases last
--- a/font.c
+++ b/font.c
@@ -12,6 +12,7 @@
int gl_n, gl_sz; /* number of glyphs in the font */
struct dict *gl_dict; /* mapping from gl[i].id to i */
struct dict *ch_dict; /* charset mapping */
+ struct dict *ch_map; /* character aliases */
};
/* find a glyph by its name */
@@ -18,6 +19,8 @@
struct glyph *font_find(struct font *fn, char *name)
{
int i = dict_get(fn->ch_dict, name);
+ if (i < 0) /* maybe a character alias */
+ i = dict_get(fn->ch_map, name);
return i >= 0 ? fn->gl + i : NULL;
}
@@ -79,9 +82,11 @@
if (sscanf(tok, "%d", &g->pos) != 1)
g->pos = 0;
}
+ dict_put(fn->ch_dict, name, *gid);
+ (*n)++;
+ } else {
+ dict_put(fn->ch_map, name, *gid);
}
- dict_put(fn->ch_dict, name, *gid);
- (*n)++;
return 0;
}
@@ -111,6 +116,7 @@
memset(fn, 0, sizeof(*fn));
fn->gl_dict = dict_make(-1, 1);
fn->ch_dict = dict_make(-1, 1);
+ fn->ch_map = dict_make(-1, 1);
while (fscanf(fin, "%s", tok) == 1) {
if (!strcmp("char", tok)) {
font_readchar(fn, fin, &ch_n, &ch_g);
@@ -139,6 +145,7 @@
{
dict_free(fn->gl_dict);
dict_free(fn->ch_dict);
+ dict_free(fn->ch_map);
free(fn->gl);
free(fn);
}