| 1 |
#include "gsub-single.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 |
bool consolidate_gsub_single(otfcc_Font *font, table_OTL *table, otl_Subtable *_subtable, |
| 14 |
const otfcc_Options *options) { |
| 15 |
subtable_gsub_single *subtable = &(_subtable->gsub_single); |
| 16 |
gsub_single_map_hash *h = NULL; |
| 17 |
for (size_t k = 0; k < subtable->length; k++) { |
| 18 |
if (!GlyphOrder.consolidateHandle(font->glyph_order, &subtable->items[k].from)) { |
| 19 |
logWarning("[Consolidate] Ignored missing glyph /%s.\n", subtable->items[k].from.name); |
| 20 |
continue; |
| 21 |
} |
| 22 |
if (!GlyphOrder.consolidateHandle(font->glyph_order, &subtable->items[k].to)) { |
| 23 |
logWarning("[Consolidate] Ignored missing glyph /%s.\n", subtable->items[k].to.name); |
| 24 |
continue; |
| 25 |
} |
| 26 |
gsub_single_map_hash *s; |
| 27 |
int fromid = subtable->items[k].from.index; |
| 28 |
HASH_FIND_INT(h, &fromid, s); |
| 29 |
if (s) { |
| 30 |
logWarning("[Consolidate] Double-mapping a glyph in a single substitution /%s.\n", |
| 31 |
subtable->items[k].from.name); |
| 32 |
} else { |
| 33 |
NEW(s); |
| 34 |
s->fromid = subtable->items[k].from.index; |
| 35 |
s->toid = subtable->items[k].to.index; |
| 36 |
s->fromname = sdsdup(subtable->items[k].from.name); |
| 37 |
s->toname = sdsdup(subtable->items[k].to.name); |
| 38 |
HASH_ADD_INT(h, fromid, s); |
| 39 |
} |
| 40 |
} |
| 41 |
HASH_SORT(h, by_from_id); |
| 42 |
if (HASH_COUNT(h) != subtable->length) { logWarning("[Consolidate] In this lookup, some mappings are ignored.\n"); } |
| 43 |
|
| 44 |
iSubtable_gsub_single.clear(subtable); |
| 45 |
gsub_single_map_hash *s, *tmp; |
| 46 |
HASH_ITER(hh, h, s, tmp) { |
| 47 |
iSubtable_gsub_single.push(subtable, |
| 48 |
((otl_GsubSingleEntry){.from = Handle.fromConsolidated(s->fromid, s->fromname), |
| 49 |
.to = Handle.fromConsolidated(s->toid, s->toname)})); |
| 50 |
sdsfree(s->fromname); |
| 51 |
sdsfree(s->toname); |
| 52 |
HASH_DEL(h, s); |
| 53 |
FREE(s); |
| 54 |
} |
| 55 |
return (subtable->length == 0); |
| 56 |
} |