| 1 |
#include "private.h" |
| 2 |
|
| 3 |
static void _declare_lookup_dumper(otl_LookupType llt, const char *lt, json_value *(*dumper)(const otl_Subtable *st), |
| 4 |
otl_Lookup *lookup, json_value *dump) { |
| 5 |
if (lookup->type == llt) { |
| 6 |
json_object_push(dump, "type", json_string_new(lt)); |
| 7 |
json_object_push(dump, "flags", otfcc_dump_flags(lookup->flags, lookupFlagsLabels)); |
| 8 |
if (lookup->flags >> 8) { json_object_push(dump, "markAttachmentType", json_integer_new(lookup->flags >> 8)); } |
| 9 |
json_value *subtables = json_array_new(lookup->subtables.length); |
| 10 |
for (tableid_t j = 0; j < lookup->subtables.length; j++) |
| 11 |
if (lookup->subtables.items[j]) { json_array_push(subtables, dumper(lookup->subtables.items[j])); } |
| 12 |
json_object_push(dump, "subtables", subtables); |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
#define LOOKUP_DUMPER(llt, fn) _declare_lookup_dumper(llt, tableNames[llt], fn, lookup, dump); |
| 17 |
|
| 18 |
static void _dump_lookup(otl_Lookup *lookup, json_value *dump) { |
| 19 |
LOOKUP_DUMPER(otl_type_gsub_single, otl_gsub_dump_single); |
| 20 |
LOOKUP_DUMPER(otl_type_gsub_multiple, otl_gsub_dump_multi); |
| 21 |
LOOKUP_DUMPER(otl_type_gsub_alternate, otl_gsub_dump_multi); |
| 22 |
LOOKUP_DUMPER(otl_type_gsub_ligature, otl_gsub_dump_ligature); |
| 23 |
LOOKUP_DUMPER(otl_type_gsub_chaining, otl_dump_chaining); |
| 24 |
LOOKUP_DUMPER(otl_type_gsub_reverse, otl_gsub_dump_reverse); |
| 25 |
LOOKUP_DUMPER(otl_type_gpos_chaining, otl_dump_chaining); |
| 26 |
LOOKUP_DUMPER(otl_type_gpos_single, otl_gpos_dump_single); |
| 27 |
LOOKUP_DUMPER(otl_type_gpos_pair, otl_gpos_dump_pair); |
| 28 |
LOOKUP_DUMPER(otl_type_gpos_cursive, otl_gpos_dump_cursive); |
| 29 |
LOOKUP_DUMPER(otl_type_gpos_markToBase, otl_gpos_dump_markToSingle); |
| 30 |
LOOKUP_DUMPER(otl_type_gpos_markToMark, otl_gpos_dump_markToSingle); |
| 31 |
LOOKUP_DUMPER(otl_type_gpos_markToLigature, otl_gpos_dump_markToLigature); |
| 32 |
} |
| 33 |
|
| 34 |
void otfcc_dumpOtl(const table_OTL *table, json_value *root, const otfcc_Options *options, const char *tag) { |
| 35 |
if (!table || !table->languages.length || !table->lookups.length || !table->features.length) return; |
| 36 |
loggedStep("%s", tag) { |
| 37 |
json_value *otl = json_object_new(3); |
| 38 |
loggedStep("Languages") { |
| 39 |
// dump script list |
| 40 |
json_value *languages = json_object_new(table->languages.length); |
| 41 |
for (tableid_t j = 0; j < table->languages.length; j++) { |
| 42 |
json_value *_lang = json_object_new(5); |
| 43 |
otl_LanguageSystem *lang = table->languages.items[j]; |
| 44 |
if (lang->requiredFeature) { |
| 45 |
json_object_push(_lang, "requiredFeature", json_string_new(lang->requiredFeature->name)); |
| 46 |
} |
| 47 |
json_value *features = json_array_new(lang->features.length); |
| 48 |
for (tableid_t k = 0; k < lang->features.length; k++) |
| 49 |
if (lang->features.items[k]) { |
| 50 |
json_array_push(features, json_string_new(lang->features.items[k]->name)); |
| 51 |
} |
| 52 |
json_object_push(_lang, "features", preserialize(features)); |
| 53 |
json_object_push(languages, lang->name, _lang); |
| 54 |
} |
| 55 |
json_object_push(otl, "languages", languages); |
| 56 |
} |
| 57 |
loggedStep("Features") { |
| 58 |
// dump feature list |
| 59 |
json_value *features = json_object_new(table->features.length); |
| 60 |
for (tableid_t j = 0; j < table->features.length; j++) { |
| 61 |
otl_Feature *feature = table->features.items[j]; |
| 62 |
json_value *_feature = json_array_new(feature->lookups.length); |
| 63 |
for (tableid_t k = 0; k < feature->lookups.length; k++) |
| 64 |
if (feature->lookups.items[k]) { |
| 65 |
json_array_push(_feature, json_string_new(feature->lookups.items[k]->name)); |
| 66 |
} |
| 67 |
json_object_push(features, feature->name, preserialize(_feature)); |
| 68 |
} |
| 69 |
json_object_push(otl, "features", features); |
| 70 |
} |
| 71 |
loggedStep("Lookups") { |
| 72 |
// dump lookups |
| 73 |
json_value *lookups = json_object_new(table->lookups.length); |
| 74 |
json_value *lookupOrder = json_array_new(table->lookups.length); |
| 75 |
for (tableid_t j = 0; j < table->lookups.length; j++) { |
| 76 |
json_value *_lookup = json_object_new(5); |
| 77 |
otl_Lookup *lookup = table->lookups.items[j]; |
| 78 |
_dump_lookup(lookup, _lookup); |
| 79 |
json_object_push(lookups, lookup->name, _lookup); |
| 80 |
json_array_push(lookupOrder, json_string_new(lookup->name)); |
| 81 |
} |
| 82 |
json_object_push(otl, "lookups", lookups); |
| 83 |
json_object_push(otl, "lookupOrder", lookupOrder); |
| 84 |
} |
| 85 |
json_object_push(root, tag, otl); |
| 86 |
} |
| 87 |
} |