| 1 |
#include "gpos-single.h" |
| 2 |
|
| 3 |
typedef struct { |
| 4 |
int fromid; |
| 5 |
sds fromname; |
| 6 |
otl_PositionValue v; |
| 7 |
UT_hash_handle hh; |
| 8 |
} gpos_single_hash; |
| 9 |
static int gpos_by_from_id(gpos_single_hash *a, gpos_single_hash *b) { |
| 10 |
return a->fromid - b->fromid; |
| 11 |
} |
| 12 |
|
| 13 |
bool consolidate_gpos_single(otfcc_Font *font, table_OTL *table, otl_Subtable *_subtable, |
| 14 |
const otfcc_Options *options) { |
| 15 |
subtable_gpos_single *subtable = &(_subtable->gpos_single); |
| 16 |
gpos_single_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", |
| 20 |
subtable->items[k].target.name); |
| 21 |
continue; |
| 22 |
} |
| 23 |
gpos_single_hash *s; |
| 24 |
int fromid = subtable->items[k].target.index; |
| 25 |
HASH_FIND_INT(h, &fromid, s); |
| 26 |
if (s) { |
| 27 |
logWarning("[Consolidate] Detected glyph double-mapping about /%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->v = subtable->items[k].value; |
| 34 |
HASH_ADD_INT(h, fromid, s); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
HASH_SORT(h, gpos_by_from_id); |
| 39 |
iSubtable_gpos_single.clear(subtable); |
| 40 |
|
| 41 |
gpos_single_hash *s, *tmp; |
| 42 |
HASH_ITER(hh, h, s, tmp) { |
| 43 |
iSubtable_gpos_single.push( |
| 44 |
subtable, ((otl_GposSingleEntry){ |
| 45 |
.target = Handle.fromConsolidated(s->fromid, s->fromname), .value = s->v, |
| 46 |
})); |
| 47 |
sdsfree(s->fromname); |
| 48 |
HASH_DEL(h, s); |
| 49 |
FREE(s); |
| 50 |
} |
| 51 |
|
| 52 |
return (subtable->length == 0); |
| 53 |
} |