Debian Codegraph @

texk/web2c/luatexdir/font/pdfglyphtounicode-luatex.c

raw
1 static void set_glyph_unicode(char *s, glyph_unicode_entry * gp)
2 {
3 char buf[SMALL_BUF_SIZE], buf2[SMALL_BUF_SIZE], *p;
4 long code;
5 boolean last_component;
6 glyph_unicode_entry tmp, *ptmp;
7 /*tex Skip dummy entries. */
8 if (s == NULL || s == notdef)
9 return;
10 /*tex Strip everything after the first dot. */
11 p = strchr(s, '.');
12 if (p != NULL) {
13 *buf = 0;
14 strncat(buf, s, (size_t) (p - s));
15 s = buf;
16 }
17 if (strlen(s) == 0)
18 return;
19 /*tex Check for case of multiple components separated by |_|. */
20 p = strchr(s, '_');
21 if (p != NULL) {
22 assert(strlen(s) < sizeof(buf));
23 if (s != buf) {
24 strcpy(buf, s);
25 p = strchr(buf, '_');
26 s = buf;
27 }
28 *buf2 = 0;
29 last_component = false;
30 for (;;) {
31 *p = 0;
32 tmp.code = UNI_UNDEF;
33 set_glyph_unicode(s, &tmp);
34 switch (tmp.code) {
35 case UNI_UNDEF:
36 /*tex Not found, do nothing. */
37 break;
38 case UNI_STRING:
39 /*tex |s| matched an entry with string value in the database. */
40 assert(tmp.unicode_seq != NULL);
41 assert(strlen(buf2) + strlen(tmp.unicode_seq) < sizeof(buf2));
42 strcat(buf2, tmp.unicode_seq);
43 break;
44 case UNI_EXTRA_STRING:
45 /*tex |s| is a multiple value of form "uniXXXX" */
46 assert(strlen(buf2) + strlen(tmp.unicode_seq) < sizeof(buf2));
47 strcat(buf2, tmp.unicode_seq);
48 xfree(tmp.unicode_seq);
49 break;
50 default:
51 /*tex
52 |s| matched an entry with numeric value in the database, or a
53 value derived from |uXXXX|.
54 */
55 assert(tmp.code >= 0);
56 strcat(buf2, utf16be_str(tmp.code));
57 }
58 if (last_component)
59 break;
60 s = p + 1;
61 p = strchr(s, '_');
62 if (p == NULL) {
63 p = strend(s);
64 last_component = true;
65 }
66 }
67 gp->code = UNI_EXTRA_STRING;
68 gp->unicode_seq = xstrdup(buf2);
69 return;
70 }
71 /*tex Lookup glyph name in the database. */
72 tmp.name = s;
73 tmp.code = UNI_UNDEF;
74 ptmp = (glyph_unicode_entry *) avl_find(glyph_unicode_tree, &tmp);
75 if (ptmp != NULL) {
76 gp->code = ptmp->code;
77 gp->unicode_seq = ptmp->unicode_seq;
78 return;
79 }
80 /*tex Check for case of |uniXXXX|, multiple 4-hex-digit values allowed. */
81 if (str_prefix(s, "uni")) {
82 p = s + strlen("uni");
83 code = check_unicode_value(p, true);
84 if (code != UNI_UNDEF) {
85 if (strlen(p) == 4) {
86 /*tex Single value: */
87 gp->code = code;
88 } else {
89 /*tex Multiple value: */
90 gp->code = UNI_EXTRA_STRING;
91 gp->unicode_seq = xstrdup(p);
92 }
93 }
94 /*tex Since the last case cannot happen: */
95 return;
96 }
97 /*tex Check for case of |uXXXX|, a single value up to 6 hex digits. */
98 if (str_prefix(s, "u")) {
99 p = s + strlen("u");
100 code = check_unicode_value(p, false);
101 if (code != UNI_UNDEF) {
102 assert(code >= 0);
103 gp->code = code;
104 }
105 }
106 }