| 1 |
static void set_glyph_unicode(const char *s, const char* tfmname, |
| 2 |
glyph_unicode_entry *gp) |
| 3 |
{ |
| 4 |
char buf[SMALL_BUF_SIZE], buf2[SMALL_BUF_SIZE], *p; |
| 5 |
const char *p2; /* p2 points in s; p above points in writable copies */ |
| 6 |
long code; |
| 7 |
boolean last_component; |
| 8 |
glyph_unicode_entry tmp, *ptmp; |
| 9 |
/*tex Skip dummy entries. */ |
| 10 |
if (s == NULL || s == notdef) |
| 11 |
return; |
| 12 |
/*tex Strip everything after the first dot. */ |
| 13 |
p = strchr(s, '.'); |
| 14 |
if (p != NULL) { |
| 15 |
*buf = 0; |
| 16 |
strncat(buf, s, p - s); |
| 17 |
s = buf; |
| 18 |
} |
| 19 |
if (strlen(s) == 0) |
| 20 |
return; |
| 21 |
/*tex Check for case of multiple components separated by |_|. */ |
| 22 |
p = strchr(s, '_'); |
| 23 |
if (p != NULL) { |
| 24 |
assert(strlen(s) < sizeof(buf)); |
| 25 |
if (s != buf) { |
| 26 |
strcpy(buf, s); |
| 27 |
p = strchr(buf, '_'); |
| 28 |
s = buf; |
| 29 |
} |
| 30 |
*buf2 = 0; |
| 31 |
last_component = false; |
| 32 |
for (;;) { |
| 33 |
*p = 0; |
| 34 |
tmp.code = UNI_UNDEF; |
| 35 |
set_glyph_unicode(s, tfmname, &tmp); |
| 36 |
switch (tmp.code) { |
| 37 |
case UNI_UNDEF: |
| 38 |
/*tex Not found, do nothing. */ |
| 39 |
break; |
| 40 |
case UNI_STRING: |
| 41 |
/*tex |s| matched an entry with string value in the database. */ |
| 42 |
assert(tmp.unicode_seq != NULL); |
| 43 |
assert(strlen(buf2) + strlen(tmp.unicode_seq) < sizeof(buf2)); |
| 44 |
strcat(buf2, tmp.unicode_seq); |
| 45 |
break; |
| 46 |
case UNI_EXTRA_STRING: |
| 47 |
/*tex |s| is a multiple value of form "uniXXXX" */ |
| 48 |
assert(strlen(buf2) + strlen(tmp.unicode_seq) < sizeof(buf2)); |
| 49 |
strcat(buf2, tmp.unicode_seq); |
| 50 |
xfree(tmp.unicode_seq); |
| 51 |
break; |
| 52 |
default: |
| 53 |
/*tex |
| 54 |
|s| matched an entry with numeric value in the database, or a |
| 55 |
value derived from |uXXXX|. |
| 56 |
*/ |
| 57 |
assert(tmp.code >= 0); |
| 58 |
strcat(buf2, utf16be_str(tmp.code)); |
| 59 |
} |
| 60 |
if (last_component) |
| 61 |
break; |
| 62 |
s = p + 1; |
| 63 |
p = strchr(s, '_'); |
| 64 |
if (p == NULL) { |
| 65 |
p = strend(s); |
| 66 |
last_component = true; |
| 67 |
} |
| 68 |
} |
| 69 |
gp->code = UNI_EXTRA_STRING; |
| 70 |
gp->unicode_seq = xstrdup(buf2); |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
/* Glyph name search strategy: first look up the glyph name in the |
| 75 |
tfm's namespace, failing that look it up in the main database. */ |
| 76 |
/* Note: buf may alias s in the code below, but s and buf2 are |
| 77 |
guaranteed to be distinct because the code changing buf2 above |
| 78 |
always returns before reaching the code below. */ |
| 79 |
|
| 80 |
/* lookup for glyph name in the tfm's namespace */ |
| 81 |
snprintf(buf2, SMALL_BUF_SIZE, "tfm:%s/%s", tfmname, s); |
| 82 |
tmp.name = buf2; |
| 83 |
tmp.code = UNI_UNDEF; |
| 84 |
ptmp = (glyph_unicode_entry *) avl_find(glyph_unicode_tree, &tmp); |
| 85 |
if (ptmp != NULL) { |
| 86 |
gp->code = ptmp->code; |
| 87 |
gp->unicode_seq = ptmp->unicode_seq; |
| 88 |
return; |
| 89 |
} |
| 90 |
|
| 91 |
/* lookup for glyph name in the main database */ |
| 92 |
snprintf(buf2, SMALL_BUF_SIZE, "%s", s); |
| 93 |
tmp.name = buf2; |
| 94 |
tmp.code = UNI_UNDEF; |
| 95 |
ptmp = (glyph_unicode_entry *) avl_find(glyph_unicode_tree, &tmp); |
| 96 |
if (ptmp != NULL) { |
| 97 |
gp->code = ptmp->code; |
| 98 |
gp->unicode_seq = ptmp->unicode_seq; |
| 99 |
return; |
| 100 |
} |
| 101 |
|
| 102 |
/*tex Check for case of |uniXXXX|, multiple 4-hex-digit values allowed. */ |
| 103 |
if (str_prefix(s, "uni")) { |
| 104 |
p2 = s + strlen("uni"); |
| 105 |
code = check_unicode_value(p2, true); |
| 106 |
if (code != UNI_UNDEF) { |
| 107 |
if (strlen(p2) == 4) /* single value */ |
| 108 |
gp->code = code; |
| 109 |
else { /* multiple value */ |
| 110 |
gp->code = UNI_EXTRA_STRING; |
| 111 |
gp->unicode_seq = xstrdup(p2); |
| 112 |
} |
| 113 |
} |
| 114 |
/*tex Since the last case cannot happen: */ |
| 115 |
return; |
| 116 |
} |
| 117 |
/*tex Check for case of |uXXXX|, a single value up to 6 hex digits. */ |
| 118 |
if (str_prefix(s, "u")) { |
| 119 |
p2 = s + strlen("u"); |
| 120 |
code = check_unicode_value(p2, false); |
| 121 |
if (code != UNI_UNDEF) { |
| 122 |
assert(code >= 0); |
| 123 |
gp->code = code; |
| 124 |
} |
| 125 |
} |
| 126 |
} |