| 1 |
#include "otfcc/sfnt.h" |
| 2 |
#include "otfcc/font.h" |
| 3 |
#include "otfcc/sfnt-builder.h" |
| 4 |
|
| 5 |
#ifdef _WIN32 |
| 6 |
#ifndef _MSC_VER /* static link --ak */ |
| 7 |
#define OTFCC_DLL_EXPORT __declspec(dllexport) |
| 8 |
#else |
| 9 |
#define OTFCC_DLL_EXPORT |
| 10 |
#endif |
| 11 |
#else |
| 12 |
#define OTFCC_DLL_EXPORT |
| 13 |
#endif |
| 14 |
|
| 15 |
caryll_Buffer *otfccbuild_json_otf(uint32_t inlen, const char *injson, uint8_t olevel,bool for_webfont); |
| 16 |
size_t otfcc_get_buf_len(caryll_Buffer *buf); |
| 17 |
uint8_t *otfcc_get_buf_data(caryll_Buffer *buf); |
| 18 |
void otfccbuild_free_otfbuf(caryll_Buffer *buf); |
| 19 |
|
| 20 |
OTFCC_DLL_EXPORT caryll_Buffer *otfccbuild_json_otf(uint32_t inlen, const char *injson, uint8_t olevel, |
| 21 |
bool for_webfont) { |
| 22 |
otfcc_Options *options = otfcc_newOptions(); |
| 23 |
options->logger = otfcc_newLogger(otfcc_newEmptyTarget()); |
| 24 |
options->logger->indent(options->logger, "otfccbuild"); |
| 25 |
|
| 26 |
// optimization levels |
| 27 |
otfcc_Options_optimizeTo(options, olevel); |
| 28 |
if (for_webfont) { |
| 29 |
options->ignore_glyph_order = true; |
| 30 |
options->force_cid = true; |
| 31 |
} |
| 32 |
|
| 33 |
// json parsing |
| 34 |
json_value *jsonRoot = json_parse(injson, inlen); |
| 35 |
if (!jsonRoot) { return NULL; } |
| 36 |
// font parsing |
| 37 |
otfcc_IFontBuilder *parser = otfcc_newJsonReader(); |
| 38 |
otfcc_Font *font = parser->read(jsonRoot, 0, options); |
| 39 |
parser->free(parser); |
| 40 |
json_value_free(jsonRoot); |
| 41 |
if (!font) { return NULL; } |
| 42 |
|
| 43 |
// consolidation and build |
| 44 |
otfcc_iFont.consolidate(font, options); |
| 45 |
otfcc_IFontSerializer *writer = otfcc_newOTFWriter(); |
| 46 |
caryll_Buffer *otf = (caryll_Buffer *)writer->serialize(font, options); |
| 47 |
|
| 48 |
writer->free(writer); |
| 49 |
otfcc_iFont.free(font); |
| 50 |
return otf; |
| 51 |
} |
| 52 |
|
| 53 |
OTFCC_DLL_EXPORT size_t otfcc_get_buf_len(caryll_Buffer *buf) { |
| 54 |
return buf->size; |
| 55 |
} |
| 56 |
OTFCC_DLL_EXPORT uint8_t *otfcc_get_buf_data(caryll_Buffer *buf) { |
| 57 |
return buf->data; |
| 58 |
} |
| 59 |
OTFCC_DLL_EXPORT void otfccbuild_free_otfbuf(caryll_Buffer *buf) { |
| 60 |
buffree(buf); |
| 61 |
} |