| 1 |
#include "gpos-cursive.h" |
| 2 |
|
| 3 |
typedef struct { |
| 4 |
int fromid; |
| 5 |
sds fromname; |
| 6 |
otl_Anchor enter; |
| 7 |
otl_Anchor exit; |
| 8 |
UT_hash_handle hh; |
| 9 |
} gpos_cursive_hash; |
| 10 |
static int gpos_cursive_by_from_id(gpos_cursive_hash *a, gpos_cursive_hash *b) { |
| 11 |
return a->fromid - b->fromid; |
| 12 |
} |
| 13 |
bool consolidate_gpos_cursive(otfcc_Font *font, table_OTL *table, otl_Subtable *_subtable, |
| 14 |
const otfcc_Options *options) { |
| 15 |
subtable_gpos_cursive *subtable = &(_subtable->gpos_cursive); |
| 16 |
gpos_cursive_hash *h = NULL; |
| 17 |
for (glyphid_t k = 0; k < subtable->length; k++) { |
| 18 |
if (!GlyphOrder.consolidateHandle(font->glyph_order, &subtable->items[k].target)) { |
| 19 |
logWarning("[Consolidate] Ignored missing glyph /%s.\n", subtable->items[k].target.name); |
| 20 |
continue; |
| 21 |
} |
| 22 |
|
| 23 |
gpos_cursive_hash *s; |
| 24 |
int fromid = subtable->items[k].target.index; |
| 25 |
HASH_FIND_INT(h, &fromid, s); |
| 26 |
if (s) { |
| 27 |
logWarning("[Consolidate] Double-mapping a glyph in a cursive positioning /%s.\n", |
| 28 |
subtable->items[k].target.name); |
| 29 |
} else { |
| 30 |
NEW(s); |
| 31 |
s->fromid = subtable->items[k].target.index; |
| 32 |
s->fromname = sdsdup(subtable->items[k].target.name); |
| 33 |
s->enter = subtable->items[k].enter; |
| 34 |
s->exit = subtable->items[k].exit; |
| 35 |
HASH_ADD_INT(h, fromid, s); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
HASH_SORT(h, gpos_cursive_by_from_id); |
| 40 |
iSubtable_gpos_cursive.clear(subtable); |
| 41 |
|
| 42 |
gpos_cursive_hash *s, *tmp; |
| 43 |
HASH_ITER(hh, h, s, tmp) { |
| 44 |
iSubtable_gpos_cursive.push( |
| 45 |
subtable, ((otl_GposCursiveEntry){ |
| 46 |
.target = Handle.fromConsolidated(s->fromid, s->fromname), .enter = s->enter, .exit = s->exit, |
| 47 |
})); |
| 48 |
sdsfree(s->fromname); |
| 49 |
HASH_DEL(h, s); |
| 50 |
FREE(s); |
| 51 |
} |
| 52 |
|
| 53 |
return (subtable->length == 0); |
| 54 |
} |