| 1 |
#include "fpgm-prep.h" |
| 2 |
|
| 3 |
#include "support/util.h" |
| 4 |
#include "support/ttinstr/ttinstr.h" |
| 5 |
|
| 6 |
static INLINE void disposeFpgmPrep(MOVE table_fpgm_prep *table) { |
| 7 |
if (table->tag) sdsfree(table->tag); |
| 8 |
if (table->bytes) FREE(table->bytes); |
| 9 |
} |
| 10 |
|
| 11 |
caryll_standardRefType(table_fpgm_prep, table_iFpgm_prep, disposeFpgmPrep); |
| 12 |
|
| 13 |
table_fpgm_prep *otfcc_readFpgmPrep(const otfcc_Packet packet, const otfcc_Options *options, |
| 14 |
uint32_t tag) { |
| 15 |
table_fpgm_prep *t = NULL; |
| 16 |
FOR_TABLE(tag, table) { |
| 17 |
font_file_pointer data = table.data; |
| 18 |
uint32_t length = table.length; |
| 19 |
t = table_iFpgm_prep.create(); |
| 20 |
t->tag = NULL; |
| 21 |
t->length = length; |
| 22 |
NEW(t->bytes, length); |
| 23 |
if (!t->bytes) goto FAIL; |
| 24 |
memcpy(t->bytes, data, length); |
| 25 |
return t; |
| 26 |
FAIL: |
| 27 |
table_iFpgm_prep.free(t); |
| 28 |
t = NULL; |
| 29 |
} |
| 30 |
return NULL; |
| 31 |
} |
| 32 |
|
| 33 |
void table_dumpTableFpgmPrep(const table_fpgm_prep *table, json_value *root, |
| 34 |
const otfcc_Options *options, const char *tag) { |
| 35 |
if (!table) return; |
| 36 |
loggedStep("%s", tag) { |
| 37 |
json_object_push(root, tag, dump_ttinstr(table->bytes, table->length, options)); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
static void makeFpgmPrepInstr(void *_t, uint8_t *instrs, uint32_t length) { |
| 42 |
table_fpgm_prep *t = (table_fpgm_prep *)_t; |
| 43 |
t->length = length; |
| 44 |
t->bytes = instrs; |
| 45 |
} |
| 46 |
static void wrongFpgmPrepInstr(void *_t, const char *reason, int pos) { |
| 47 |
/* |
| 48 |
table_fpgm_prep *t = (table_fpgm_prep *)_t; |
| 49 |
fprintf(stderr, "[OTFCC] TrueType instructions parse error : %s, at %d in /%s\n", reason, pos, |
| 50 |
t->tag); |
| 51 |
*/ |
| 52 |
} |
| 53 |
|
| 54 |
table_fpgm_prep *otfcc_parseFpgmPrep(const json_value *root, const otfcc_Options *options, |
| 55 |
const char *tag) { |
| 56 |
table_fpgm_prep *t = NULL; |
| 57 |
json_value *table = NULL; |
| 58 |
if ((table = json_obj_get(root, tag))) { |
| 59 |
loggedStep("%s", tag) { |
| 60 |
t = table_iFpgm_prep.create(); |
| 61 |
t->tag = sdsnew(tag); |
| 62 |
parse_ttinstr(table, t, makeFpgmPrepInstr, wrongFpgmPrepInstr); |
| 63 |
} |
| 64 |
} |
| 65 |
return t; |
| 66 |
} |
| 67 |
|
| 68 |
caryll_Buffer *otfcc_buildFpgmPrep(const table_fpgm_prep *table, const otfcc_Options *options) { |
| 69 |
if (!table) return NULL; |
| 70 |
caryll_Buffer *buf = bufnew(); |
| 71 |
bufwrite_bytes(buf, table->length, table->bytes); |
| 72 |
return buf; |
| 73 |
} |