Debian Codegraph @

texk/xdvipsk/charcode.c

raw
1 /*
2 * charcode.c
3 * This routine handles the operations on chardesctype hash table
4 * and replaces original font chardesc array operations.
5 */
6 #include "xdvips.h" /* The copyright notice in that file is included too!*/
7
8 #include "uthash.h"
9 /*
10 * The external declarations:
11 */
12 #include "protos.h"
13
14
15 chardesctype *add_chardesc(fontdesctype *f, int charcode)
16 {
17 chardesctype *s;
18
19 HASH_FIND_INT(f->chardesc_hh, &charcode, s); /* id already in the hash? */
20 if (s==NULL) {
21 s = (chardesctype*)malloc(sizeof(chardesctype));
22 s->charcode = charcode;
23 s->TFMwidth = 0;
24 s->packptr = NULL;
25 s->pixelwidth = 0;
26 s->flags = 0;
27 s->flags2 = 0;
28 s->cid = 0;
29 HASH_ADD_INT( f->chardesc_hh, charcode, s ); /* id: name of key field */
30 }
31 return s;
32 }
33
34 chardesctype *find_chardesc(fontdesctype *f, int charcode)
35 {
36 chardesctype *s;
37
38 HASH_FIND_INT( f->chardesc_hh, &charcode, s ); /* s: output pointer */
39 return s;
40 }
41
42 void delete_chardesc(fontdesctype *f, int charcode)
43 {
44 chardesctype *s;
45
46 HASH_FIND_INT(f->chardesc_hh, &charcode, s); /* id already in the hash? */
47 if (s!=NULL) {
48 HASH_DEL( f->chardesc_hh, s); /* user: pointer to deletee */
49 free(s);
50 }
51 }
52
53 void delete_all_chardesc(fontdesctype *f)
54 {
55 chardesctype *current, *tmp;
56
57 HASH_ITER(hh, f->chardesc_hh, current, tmp) {
58 HASH_DEL(f->chardesc_hh,current); /* delete it (users advances to next) */
59 free(current); /* free it */
60 }
61 }
62
63 static int charcode_sort(chardesctype *a, chardesctype *b)
64 {
65 return (a->charcode - b->charcode);
66 }
67
68 void sort_by_charcode(fontdesctype *f)
69 {
70 HASH_SORT(f->chardesc_hh, charcode_sort);
71 }