| 1 |
#include "gpos-cursive.h" |
| 2 |
#include "gpos-common.h" |
| 3 |
|
| 4 |
static void deleteGposCursiveEntry(otl_GposCursiveEntry *entry) { |
| 5 |
Handle.dispose(&entry->target); |
| 6 |
} |
| 7 |
|
| 8 |
static caryll_ElementInterface(otl_GposCursiveEntry) gss_typeinfo = { |
| 9 |
.init = NULL, .copy = NULL, .dispose = deleteGposCursiveEntry}; |
| 10 |
|
| 11 |
caryll_standardVectorImpl(subtable_gpos_cursive, otl_GposCursiveEntry, gss_typeinfo, |
| 12 |
iSubtable_gpos_cursive); |
| 13 |
|
| 14 |
otl_Subtable *otl_read_gpos_cursive(const font_file_pointer data, uint32_t tableLength, |
| 15 |
uint32_t offset, const glyphid_t maxGlyphs, |
| 16 |
const otfcc_Options *options) { |
| 17 |
subtable_gpos_cursive *subtable = iSubtable_gpos_cursive.create(); |
| 18 |
otl_Coverage *targets = NULL; |
| 19 |
|
| 20 |
checkLength(offset + 6); |
| 21 |
|
| 22 |
targets = Coverage.read(data, tableLength, offset + read_16u(data + offset + 2)); |
| 23 |
if (!targets || targets->numGlyphs == 0) goto FAIL; |
| 24 |
|
| 25 |
glyphid_t valueCount = read_16u(data + offset + 4); |
| 26 |
checkLength(offset + 6 + 4 * valueCount); |
| 27 |
if (valueCount != targets->numGlyphs) goto FAIL; |
| 28 |
|
| 29 |
for (glyphid_t j = 0; j < valueCount; j++) { |
| 30 |
uint16_t enterOffset = read_16u(data + offset + 6 + 4 * j); |
| 31 |
uint16_t exitOffset = read_16u(data + offset + 6 + 4 * j + 2); |
| 32 |
otl_Anchor enter = otl_anchor_absent(); |
| 33 |
otl_Anchor exit = otl_anchor_absent(); |
| 34 |
if (enterOffset) { enter = otl_read_anchor(data, tableLength, offset + enterOffset); } |
| 35 |
if (exitOffset) { exit = otl_read_anchor(data, tableLength, offset + exitOffset); } |
| 36 |
iSubtable_gpos_cursive.push( |
| 37 |
subtable, ((otl_GposCursiveEntry){ |
| 38 |
.target = Handle.dup(targets->glyphs[j]), .enter = enter, .exit = exit})); |
| 39 |
} |
| 40 |
if (targets) Coverage.free(targets); |
| 41 |
return (otl_Subtable *)subtable; |
| 42 |
FAIL: |
| 43 |
if (targets) Coverage.free(targets); |
| 44 |
iSubtable_gpos_cursive.free(subtable); |
| 45 |
return NULL; |
| 46 |
} |
| 47 |
|
| 48 |
json_value *otl_gpos_dump_cursive(const otl_Subtable *_subtable) { |
| 49 |
const subtable_gpos_cursive *subtable = &(_subtable->gpos_cursive); |
| 50 |
json_value *st = json_object_new(subtable->length); |
| 51 |
for (glyphid_t j = 0; j < subtable->length; j++) { |
| 52 |
json_value *rec = json_object_new(2); |
| 53 |
json_object_push(rec, "enter", otl_dump_anchor(subtable->items[j].enter)); |
| 54 |
json_object_push(rec, "exit", otl_dump_anchor(subtable->items[j].exit)); |
| 55 |
json_object_push(st, subtable->items[j].target.name, preserialize(rec)); |
| 56 |
} |
| 57 |
return st; |
| 58 |
} |
| 59 |
|
| 60 |
otl_Subtable *otl_gpos_parse_cursive(const json_value *_subtable, const otfcc_Options *options) { |
| 61 |
subtable_gpos_cursive *subtable = iSubtable_gpos_cursive.create(); |
| 62 |
for (glyphid_t j = 0; j < _subtable->u.object.length; j++) { |
| 63 |
if (_subtable->u.object.values[j].value && |
| 64 |
_subtable->u.object.values[j].value->type == json_object) { |
| 65 |
sds gname = sdsnewlen(_subtable->u.object.values[j].name, |
| 66 |
_subtable->u.object.values[j].name_length); |
| 67 |
iSubtable_gpos_cursive.push( |
| 68 |
subtable, ((otl_GposCursiveEntry){ |
| 69 |
.target = Handle.fromName(gname), |
| 70 |
.enter = otl_parse_anchor( |
| 71 |
json_obj_get(_subtable->u.object.values[j].value, "enter")), |
| 72 |
.exit = otl_parse_anchor( |
| 73 |
json_obj_get(_subtable->u.object.values[j].value, "exit")), |
| 74 |
})); |
| 75 |
} |
| 76 |
} |
| 77 |
return (otl_Subtable *)subtable; |
| 78 |
} |
| 79 |
|
| 80 |
caryll_Buffer *otfcc_build_gpos_cursive(const otl_Subtable *_subtable, |
| 81 |
otl_BuildHeuristics heuristics) { |
| 82 |
const subtable_gpos_cursive *subtable = &(_subtable->gpos_cursive); |
| 83 |
otl_Coverage *cov = Coverage.create(); |
| 84 |
for (glyphid_t j = 0; j < subtable->length; j++) { |
| 85 |
Coverage.push(cov, Handle.dup(subtable->items[j].target)); |
| 86 |
} |
| 87 |
|
| 88 |
bk_Block *root = bk_new_Block(b16, 1, // format |
| 89 |
p16, bk_newBlockFromBuffer(Coverage.build(cov)), // Coverage |
| 90 |
b16, subtable->length, // EntryExitCount |
| 91 |
bkover); |
| 92 |
for (glyphid_t j = 0; j < subtable->length; j++) { |
| 93 |
bk_push(root, // EntryExitRecord[.] |
| 94 |
p16, bkFromAnchor(subtable->items[j].enter), // enter |
| 95 |
p16, bkFromAnchor(subtable->items[j].exit), // exit |
| 96 |
bkover); |
| 97 |
} |
| 98 |
Coverage.free(cov); |
| 99 |
|
| 100 |
return bk_build_Block(root); |
| 101 |
} |