Debian Codegraph @

texk/web2c/mfluadir/otfcc/lib/table/meta/dump.c

raw
1 #include "../meta.h"
2
3 #include "support/util.h"
4
5 static INLINE bool isStringTag(uint32_t tag) {
6 return tag == OTFCC_CHR('d','l','n','g') || tag == OTFCC_CHR('s','l','n','g');
7 }
8
9 void otfcc_dumpMeta(const table_meta *meta, json_value *root, const otfcc_Options *options) {
10 if (!meta) return;
11 loggedStep("meta") {
12 json_value *_meta = json_object_new(3);
13 json_object_push(_meta, "version", json_integer_new(meta->version));
14 json_object_push(_meta, "flags", json_integer_new(meta->flags));
15 json_value *_entries = json_array_new(meta->entries.length);
16 json_object_push(_meta, "entries", _entries);
17 foreach (meta_Entry *e, meta->entries) {
18 json_value *_e = json_object_new(2);
19 char _tag[4];
20 tag2str(e->tag, _tag);
21 json_object_push(_e, "tag", json_string_new_length(4, _tag));
22 if (isStringTag(e->tag)) {
23 json_object_push(_e, "string",
24 json_string_new_length((uint32_t)sdslen(e->data), e->data));
25 } else {
26 size_t outLen = 0;
27 uint8_t *out = base64_encode((uint8_t *)e->data, sdslen(e->data), &outLen);
28 json_object_push(_e, "base64",
29 json_string_new_length((uint32_t)outLen, (char *)out));
30 FREE(out);
31 }
32 json_array_push(_entries, _e);
33 }
34 json_object_push(root, "meta", _meta);
35 }
36 }