| 1 |
#include "cvt.h" |
| 2 |
|
| 3 |
#include "support/util.h" |
| 4 |
|
| 5 |
static INLINE void disposeCvt(MOVE table_cvt *table) { |
| 6 |
if (table->words) FREE(table->words); |
| 7 |
} |
| 8 |
|
| 9 |
caryll_standardRefType(table_cvt, table_iCvt, disposeCvt); |
| 10 |
|
| 11 |
table_cvt *otfcc_readCvt(const otfcc_Packet packet, const otfcc_Options *options, uint32_t tag) { |
| 12 |
table_cvt *t = NULL; |
| 13 |
FOR_TABLE(tag, table) { |
| 14 |
font_file_pointer data = table.data; |
| 15 |
uint32_t length = table.length; |
| 16 |
NEW(t); |
| 17 |
t->length = length >> 1; |
| 18 |
NEW(t->words, (t->length + 1)); |
| 19 |
for (uint16_t j = 0; j < t->length; j++) { |
| 20 |
t->words[j] = read_16u(data + 2 * j); |
| 21 |
} |
| 22 |
return t; |
| 23 |
} |
| 24 |
return NULL; |
| 25 |
} |
| 26 |
|
| 27 |
void otfcc_dumpCvt(const table_cvt *table, json_value *root, const otfcc_Options *options, |
| 28 |
const char *tag) { |
| 29 |
if (!table) return; |
| 30 |
loggedStep("cvt") { |
| 31 |
json_value *arr = json_array_new(table->length); |
| 32 |
for (uint16_t j = 0; j < table->length; j++) { |
| 33 |
json_array_push(arr, json_integer_new(table->words[j])); |
| 34 |
} |
| 35 |
json_object_push(root, tag, arr); |
| 36 |
} |
| 37 |
} |
| 38 |
table_cvt *otfcc_parseCvt(const json_value *root, const otfcc_Options *options, const char *tag) { |
| 39 |
table_cvt *t = NULL; |
| 40 |
json_value *table = NULL; |
| 41 |
if ((table = json_obj_get_type(root, tag, json_array))) { |
| 42 |
loggedStep("cvt") { |
| 43 |
// Meaningful CVT dump |
| 44 |
NEW(t); |
| 45 |
t->length = table->u.array.length; |
| 46 |
NEW(t->words, (t->length + 1)); |
| 47 |
for (uint16_t j = 0; j < t->length; j++) { |
| 48 |
json_value *record = table->u.array.values[j]; |
| 49 |
if (record->type == json_integer) { |
| 50 |
t->words[j] = record->u.integer; |
| 51 |
} else if (record->type == json_double) { |
| 52 |
t->words[j] = (uint16_t)record->u.dbl; |
| 53 |
} else { |
| 54 |
t->words[j] = 0; |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
} else if ((table = json_obj_get_type(root, tag, json_string))) { |
| 59 |
loggedStep("cvt") { |
| 60 |
// Bytes CVT dump |
| 61 |
NEW(t); |
| 62 |
size_t len; |
| 63 |
uint8_t *raw = |
| 64 |
base64_decode((uint8_t *)table->u.string.ptr, table->u.string.length, &len); |
| 65 |
t->length = (uint32_t)(len >> 1); |
| 66 |
NEW(t->words, (t->length + 1)); |
| 67 |
for (uint16_t j = 0; j < t->length; j++) { |
| 68 |
t->words[j] = read_16u(raw + 2 * j); |
| 69 |
} |
| 70 |
FREE(raw); |
| 71 |
} |
| 72 |
} |
| 73 |
return t; |
| 74 |
} |
| 75 |
|
| 76 |
caryll_Buffer *otfcc_buildCvt(const table_cvt *table, const otfcc_Options *options) { |
| 77 |
if (!table) return NULL; |
| 78 |
caryll_Buffer *buf = bufnew(); |
| 79 |
for (uint16_t j = 0; j < table->length; j++) { |
| 80 |
bufwrite16b(buf, table->words[j]); |
| 81 |
} |
| 82 |
return buf; |
| 83 |
} |