| 1 |
#include "gsub-reverse.h" |
| 2 |
|
| 3 |
typedef struct { |
| 4 |
int fromid; |
| 5 |
sds fromname; |
| 6 |
int toid; |
| 7 |
sds toname; |
| 8 |
UT_hash_handle hh; |
| 9 |
} gsub_single_map_hash; |
| 10 |
static int by_from_id(gsub_single_map_hash *a, gsub_single_map_hash *b) { |
| 11 |
return a->fromid - b->fromid; |
| 12 |
} |
| 13 |
|
| 14 |
bool consolidate_gsub_reverse(otfcc_Font *font, table_OTL *table, otl_Subtable *_subtable, |
| 15 |
const otfcc_Options *options) { |
| 16 |
subtable_gsub_reverse *subtable = &(_subtable->gsub_reverse); |
| 17 |
for (tableid_t j = 0; j < subtable->matchCount; j++) { |
| 18 |
fontop_consolidateCoverage(font, subtable->match[j], options); |
| 19 |
} |
| 20 |
fontop_consolidateCoverage(font, subtable->to, options); |
| 21 |
if (subtable->inputIndex >= subtable->matchCount) { subtable->inputIndex = subtable->matchCount - 1; } |
| 22 |
gsub_single_map_hash *h = NULL; |
| 23 |
otl_Coverage *from = subtable->match[subtable->inputIndex]; |
| 24 |
for (glyphid_t k = 0; k < from->numGlyphs && k < subtable->to->numGlyphs; k++) { |
| 25 |
gsub_single_map_hash *s; |
| 26 |
int fromid = from->glyphs[k].index; |
| 27 |
HASH_FIND_INT(h, &fromid, s); |
| 28 |
if (s) { |
| 29 |
logWarning("[Consolidate] Double-mapping a glyph in a reverse substitution /%s.\n", from->glyphs[k].name); |
| 30 |
} else { |
| 31 |
NEW(s); |
| 32 |
s->fromid = from->glyphs[k].index; |
| 33 |
s->toid = subtable->to->glyphs[k].index; |
| 34 |
s->fromname = from->glyphs[k].name; |
| 35 |
s->toname = subtable->to->glyphs[k].name; |
| 36 |
HASH_ADD_INT(h, fromid, s); |
| 37 |
} |
| 38 |
} |
| 39 |
HASH_SORT(h, by_from_id); |
| 40 |
if (HASH_COUNT(h) != from->numGlyphs || HASH_COUNT(h) != subtable->to->numGlyphs) { |
| 41 |
logWarning("[Consolidate] In this reverse subsitution lookup, some mappings are ignored.\n"); |
| 42 |
} |
| 43 |
from->numGlyphs = HASH_COUNT(h); |
| 44 |
subtable->to->numGlyphs = HASH_COUNT(h); |
| 45 |
{ |
| 46 |
gsub_single_map_hash *s, *tmp; |
| 47 |
glyphid_t j = 0; |
| 48 |
HASH_ITER(hh, h, s, tmp) { |
| 49 |
from->glyphs[j] = Handle.fromConsolidated(s->fromid, s->fromname); |
| 50 |
subtable->to->glyphs[j] = Handle.fromConsolidated(s->toid, s->toname); |
| 51 |
j++; |
| 52 |
HASH_DEL(h, s); |
| 53 |
FREE(s); |
| 54 |
} |
| 55 |
} |
| 56 |
return false; |
| 57 |
} |