| 1 |
#include "support/util.h" |
| 2 |
#include "otfcc/font.h" |
| 3 |
#include "table/all.h" |
| 4 |
|
| 5 |
static void *serializeToJson(otfcc_Font *font, const otfcc_Options *options) { |
| 6 |
json_value *root = json_object_new(48); |
| 7 |
if (!root) return NULL; |
| 8 |
otfcc_dumpFvar(font->fvar, root, options); |
| 9 |
otfcc_dumpHead(font->head, root, options); |
| 10 |
otfcc_dumpHhea(font->hhea, root, options); |
| 11 |
otfcc_dumpMaxp(font->maxp, root, options); |
| 12 |
otfcc_dumpVhea(font->vhea, root, options); |
| 13 |
otfcc_dumpPost(font->post, root, options); |
| 14 |
otfcc_dumpOS_2(font->OS_2, root, options); |
| 15 |
otfcc_dumpName(font->name, root, options); |
| 16 |
otfcc_dumpMeta(font->meta, root, options); |
| 17 |
otfcc_dumpCmap(font->cmap, root, options); |
| 18 |
otfcc_dumpCFF(font->CFF_, root, options); |
| 19 |
|
| 20 |
GlyfIOContext ctx = {.locaIsLong = font->head->indexToLocFormat, |
| 21 |
.numGlyphs = font->maxp->numGlyphs, |
| 22 |
.nPhantomPoints = 4, |
| 23 |
.hasVerticalMetrics = !!(font->vhea), |
| 24 |
.exportFDSelect = font->CFF_ && font->CFF_->isCID, |
| 25 |
.fvar = font->fvar}; |
| 26 |
otfcc_dumpGlyf(font->glyf, root, options, &ctx); |
| 27 |
if (!options->ignore_hints) { |
| 28 |
table_dumpTableFpgmPrep(font->fpgm, root, options, "fpgm"); |
| 29 |
table_dumpTableFpgmPrep(font->prep, root, options, "prep"); |
| 30 |
otfcc_dumpCvt(font->cvt_, root, options, "cvt_"); |
| 31 |
otfcc_dumpGasp(font->gasp, root, options); |
| 32 |
} |
| 33 |
otfcc_dumpVDMX(font->VDMX, root, options); |
| 34 |
otfcc_dumpOtl(font->GSUB, root, options, "GSUB"); |
| 35 |
otfcc_dumpOtl(font->GPOS, root, options, "GPOS"); |
| 36 |
otfcc_dumpGDEF(font->GDEF, root, options); |
| 37 |
otfcc_dumpBASE(font->BASE, root, options); |
| 38 |
|
| 39 |
otfcc_dumpCPAL(font->CPAL, root, options); |
| 40 |
otfcc_dumpCOLR(font->COLR, root, options); |
| 41 |
otfcc_dumpSVG(font->SVG_, root, options); |
| 42 |
otfcc_dumpTSI(font->TSI_01, root, options, "TSI_01"); |
| 43 |
otfcc_dumpTSI(font->TSI_23, root, options, "TSI_23"); |
| 44 |
otfcc_dumpTSI5(font->TSI5, root, options); |
| 45 |
return root; |
| 46 |
} |
| 47 |
static void freeJsonWriter(otfcc_IFontSerializer *self) { |
| 48 |
free(self); |
| 49 |
} |
| 50 |
otfcc_IFontSerializer *otfcc_newJsonWriter() { |
| 51 |
otfcc_IFontSerializer *writer; |
| 52 |
NEW(writer); |
| 53 |
writer->serialize = serializeToJson; |
| 54 |
writer->free = freeJsonWriter; |
| 55 |
return writer; |
| 56 |
} |