| 1 |
#include "gsub-multi.h" |
| 2 |
|
| 3 |
static void deleteGsubMultiEntry(otl_GsubMultiEntry *entry) { |
| 4 |
Handle.dispose(&entry->from); |
| 5 |
DELETE(Coverage.free, entry->to); |
| 6 |
} |
| 7 |
|
| 8 |
static caryll_ElementInterface(otl_GsubMultiEntry) gsm_typeinfo = { |
| 9 |
.init = NULL, .copy = NULL, .dispose = deleteGsubMultiEntry}; |
| 10 |
|
| 11 |
caryll_standardVectorImpl(subtable_gsub_multi, otl_GsubMultiEntry, gsm_typeinfo, |
| 12 |
iSubtable_gsub_multi); |
| 13 |
|
| 14 |
otl_Subtable *otl_read_gsub_multi(font_file_pointer data, uint32_t tableLength, uint32_t offset, |
| 15 |
const glyphid_t maxGlyphs, const otfcc_Options *options) { |
| 16 |
subtable_gsub_multi *subtable = iSubtable_gsub_multi.create(); |
| 17 |
otl_Coverage *from = NULL; |
| 18 |
checkLength(offset + 6); |
| 19 |
|
| 20 |
from = Coverage.read(data, tableLength, offset + read_16u(data + offset + 2)); |
| 21 |
glyphid_t seqCount = read_16u(data + offset + 4); |
| 22 |
if (seqCount != from->numGlyphs) goto FAIL; |
| 23 |
checkLength(offset + 6 + seqCount * 2); |
| 24 |
|
| 25 |
for (glyphid_t j = 0; j < seqCount; j++) { |
| 26 |
uint32_t seqOffset = offset + read_16u(data + offset + 6 + j * 2); |
| 27 |
otl_Coverage *cov = Coverage.create(); |
| 28 |
glyphid_t n = read_16u(data + seqOffset); |
| 29 |
for (glyphid_t k = 0; k < n; k++) { |
| 30 |
Coverage.push(cov, Handle.fromIndex(read_16u(data + seqOffset + 2 + k * 2))); |
| 31 |
} |
| 32 |
iSubtable_gsub_multi.push(subtable, ((otl_GsubMultiEntry){ |
| 33 |
.from = Handle.dup(from->glyphs[j]), .to = cov, |
| 34 |
})); |
| 35 |
} |
| 36 |
Coverage.free(from); |
| 37 |
return (otl_Subtable *)subtable; |
| 38 |
|
| 39 |
FAIL: |
| 40 |
if (from) Coverage.free(from); |
| 41 |
iSubtable_gsub_multi.free(subtable); |
| 42 |
return NULL; |
| 43 |
} |
| 44 |
|
| 45 |
json_value *otl_gsub_dump_multi(const otl_Subtable *_subtable) { |
| 46 |
const subtable_gsub_multi *subtable = &(_subtable->gsub_multi); |
| 47 |
json_value *st = json_object_new(subtable->length); |
| 48 |
for (glyphid_t j = 0; j < subtable->length; j++) { |
| 49 |
json_object_push(st, subtable->items[j].from.name, Coverage.dump(subtable->items[j].to)); |
| 50 |
} |
| 51 |
return st; |
| 52 |
} |
| 53 |
|
| 54 |
otl_Subtable *otl_gsub_parse_multi(const json_value *_subtable, const otfcc_Options *options) { |
| 55 |
subtable_gsub_multi *st = iSubtable_gsub_multi.create(); |
| 56 |
|
| 57 |
for (glyphid_t k = 0; k < _subtable->u.object.length; k++) { |
| 58 |
json_value *_to = _subtable->u.object.values[k].value; |
| 59 |
if (!_to || _to->type != json_array) continue; |
| 60 |
iSubtable_gsub_multi.push( |
| 61 |
st, ((otl_GsubMultiEntry){ |
| 62 |
.from = Handle.fromName(sdsnewlen(_subtable->u.object.values[k].name, |
| 63 |
_subtable->u.object.values[k].name_length)), |
| 64 |
.to = Coverage.parse(_to), |
| 65 |
})); |
| 66 |
} |
| 67 |
|
| 68 |
return (otl_Subtable *)st; |
| 69 |
} |
| 70 |
|
| 71 |
caryll_Buffer *otfcc_build_gsub_multi_subtable(const otl_Subtable *_subtable, otl_BuildHeuristics heuristics) { |
| 72 |
const subtable_gsub_multi *subtable = &(_subtable->gsub_multi); |
| 73 |
otl_Coverage *cov = Coverage.create(); |
| 74 |
for (glyphid_t j = 0; j < subtable->length; j++) { |
| 75 |
Coverage.push(cov, Handle.dup(subtable->items[j].from)); |
| 76 |
} |
| 77 |
|
| 78 |
bk_Block *root = bk_new_Block(b16, 1, // format |
| 79 |
p16, bk_newBlockFromBuffer(Coverage.build(cov)), // coverage |
| 80 |
b16, subtable->length, // quantity |
| 81 |
bkover); |
| 82 |
for (glyphid_t j = 0; j < subtable->length; j++) { |
| 83 |
bk_Block *b = bk_new_Block(b16, subtable->items[j].to->numGlyphs, bkover); |
| 84 |
for (glyphid_t k = 0; k < subtable->items[j].to->numGlyphs; k++) { |
| 85 |
bk_push(b, b16, subtable->items[j].to->glyphs[k].index, bkover); |
| 86 |
} |
| 87 |
bk_push(root, p16, b, bkover); |
| 88 |
} |
| 89 |
Coverage.free(cov); |
| 90 |
return bk_build_Block(root); |
| 91 |
} |