summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/mfluadir/otfcc/src/otfccdll.c
blob: 1019bc226b66f40528c6826d1d136b1fe8eec4bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "otfcc/sfnt.h"
#include "otfcc/font.h"
#include "otfcc/sfnt-builder.h"

#ifdef _WIN32
 #ifndef _MSC_VER /* static link --ak */
#define OTFCC_DLL_EXPORT __declspec(dllexport)
 #else
#define OTFCC_DLL_EXPORT
 #endif
#else
#define OTFCC_DLL_EXPORT
#endif

caryll_Buffer *otfccbuild_json_otf(uint32_t inlen, const char *injson, uint8_t olevel,bool for_webfont);
size_t otfcc_get_buf_len(caryll_Buffer *buf);
uint8_t *otfcc_get_buf_data(caryll_Buffer *buf);
void otfccbuild_free_otfbuf(caryll_Buffer *buf);

OTFCC_DLL_EXPORT caryll_Buffer *otfccbuild_json_otf(uint32_t inlen, const char *injson, uint8_t olevel,
                                                    bool for_webfont) {
	otfcc_Options *options = otfcc_newOptions();
	options->logger = otfcc_newLogger(otfcc_newEmptyTarget());
	options->logger->indent(options->logger, "otfccbuild");

	// optimization levels
	otfcc_Options_optimizeTo(options, olevel);
	if (for_webfont) {
		options->ignore_glyph_order = true;
		options->force_cid = true;
	}

	// json parsing
	json_value *jsonRoot = json_parse(injson, inlen);
	if (!jsonRoot) { return NULL; }
	// font parsing
	otfcc_IFontBuilder *parser = otfcc_newJsonReader();
	otfcc_Font *font = parser->read(jsonRoot, 0, options);
	parser->free(parser);
	json_value_free(jsonRoot);
	if (!font) { return NULL; }

	// consolidation and build
	otfcc_iFont.consolidate(font, options);
	otfcc_IFontSerializer *writer = otfcc_newOTFWriter();
	caryll_Buffer *otf = (caryll_Buffer *)writer->serialize(font, options);

	writer->free(writer);
	otfcc_iFont.free(font);
	return otf;
}

OTFCC_DLL_EXPORT size_t otfcc_get_buf_len(caryll_Buffer *buf) {
	return buf->size;
}
OTFCC_DLL_EXPORT uint8_t *otfcc_get_buf_data(caryll_Buffer *buf) {
	return buf->data;
}
OTFCC_DLL_EXPORT void otfccbuild_free_otfbuf(caryll_Buffer *buf) {
	buffree(buf);
}