| 1 |
#include "gsub-multi.h" |
| 2 |
|
| 3 |
typedef struct { |
| 4 |
int fromid; |
| 5 |
sds fromname; |
| 6 |
otl_Coverage *to; |
| 7 |
UT_hash_handle hh; |
| 8 |
} gsub_multi_hash; |
| 9 |
static int by_from_id_multi(gsub_multi_hash *a, gsub_multi_hash *b) { |
| 10 |
return a->fromid - b->fromid; |
| 11 |
} |
| 12 |
|
| 13 |
bool consolidate_gsub_multi(otfcc_Font *font, table_OTL *table, otl_Subtable *_subtable, |
| 14 |
const otfcc_Options *options) { |
| 15 |
subtable_gsub_multi *subtable = &(_subtable->gsub_multi); |
| 16 |
gsub_multi_hash *h = NULL; |
| 17 |
|
| 18 |
for (glyphid_t k = 0; k < subtable->length; k++) { |
| 19 |
if (!GlyphOrder.consolidateHandle(font->glyph_order, &subtable->items[k].from)) { |
| 20 |
logWarning("[Consolidate] Ignored missing glyph /%s.\n", subtable->items[k].from.name); |
| 21 |
continue; |
| 22 |
} |
| 23 |
fontop_consolidateCoverage(font, subtable->items[k].to, options); |
| 24 |
Coverage.shrink(subtable->items[k].to, false); |
| 25 |
if (!subtable->items[k].to->numGlyphs) { |
| 26 |
logWarning("[Consolidate] Ignoring empty one-to-many / alternative substitution for " |
| 27 |
"glyph /%s.\n", |
| 28 |
subtable->items[k].from.name); |
| 29 |
continue; |
| 30 |
} |
| 31 |
|
| 32 |
gsub_multi_hash *s; |
| 33 |
int fromid = subtable->items[k].from.index; |
| 34 |
HASH_FIND_INT(h, &fromid, s); |
| 35 |
if (!s) { |
| 36 |
NEW(s); |
| 37 |
s->fromid = subtable->items[k].from.index; |
| 38 |
s->fromname = sdsdup(subtable->items[k].from.name); |
| 39 |
s->to = subtable->items[k].to; |
| 40 |
subtable->items[k].to = NULL; // Transfer ownership |
| 41 |
HASH_ADD_INT(h, fromid, s); |
| 42 |
} |
| 43 |
} |
| 44 |
HASH_SORT(h, by_from_id_multi); |
| 45 |
iSubtable_gsub_multi.clear(subtable); |
| 46 |
{ |
| 47 |
gsub_multi_hash *s, *tmp; |
| 48 |
HASH_ITER(hh, h, s, tmp) { |
| 49 |
iSubtable_gsub_multi.push( |
| 50 |
subtable, ((otl_GsubMultiEntry){ |
| 51 |
.from = Handle.fromConsolidated(s->fromid, s->fromname), .to = s->to, |
| 52 |
})); |
| 53 |
sdsfree(s->fromname); |
| 54 |
HASH_DEL(h, s); |
| 55 |
FREE(s); |
| 56 |
} |
| 57 |
} |
| 58 |
return (subtable->length == 0); |
| 59 |
} |
| 60 |
|
| 61 |
bool consolidate_gsub_alternative(otfcc_Font *font, table_OTL *table, otl_Subtable *_subtable, |
| 62 |
const otfcc_Options *options) { |
| 63 |
return consolidate_gsub_multi(font, table, _subtable, options); |
| 64 |
} |