Debian Codegraph @

texk/web2c/mfluadir/otfcc/lib/libcff/libcff.h

raw
1 #ifndef cff_DATA_TYPES
2 #define cff_DATA_TYPES
3
4 #include <stdint.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include "support/util.h"
9
10 #include "cff-util.h"
11 #include "cff-value.h"
12 #include "cff-index.h"
13 #include "cff-dict.h"
14 #include "cff-charset.h"
15 #include "cff-fdselect.h"
16
17 // Limits of Type2 CharSrting
18 enum {
19 type2_argument_stack = 48,
20 type2_stem_hints = 96,
21 type2_subr_nesting = 10,
22 type2_charstring_len = 65535,
23 type2_max_subrs = 65300,
24 type2_transient_array = 32,
25 };
26
27 typedef struct {
28 uint8_t major;
29 uint8_t minor;
30 uint8_t hdrSize;
31 uint8_t offSize;
32 } cff_Header;
33
34 // CFF Encoding Structures
35 typedef struct {
36 uint8_t format;
37 uint8_t ncodes;
38 uint8_t *code;
39 } cff_EncodingFormat0;
40
41 typedef struct {
42 uint8_t first;
43 uint8_t nleft;
44 } cff_EncodingRangeFormat1;
45
46 typedef struct {
47 uint8_t format;
48 uint8_t nranges;
49 cff_EncodingRangeFormat1 *range1;
50 } cff_EncodingFormat1;
51
52 typedef struct {
53 uint8_t code;
54 uint16_t glyph;
55 } cff_EncodingSupplement;
56
57 typedef struct {
58 uint8_t nsup;
59 cff_EncodingSupplement *supplement;
60 } cff_EncodingNS;
61
62 typedef struct {
63 uint32_t t;
64 union {
65 cff_EncodingFormat0 f0;
66 cff_EncodingFormat1 f1;
67 cff_EncodingNS ns;
68 };
69 } cff_Encoding;
70
71 // Predefined Encoding Types
72 enum {
73 cff_FONT_COMMON,
74 cff_FONT_CID,
75 cff_FONT_MM,
76 };
77
78 enum {
79 cff_ENC_STANDARD,
80 cff_ENC_EXPERT,
81 cff_ENC_FORMAT0,
82 cff_ENC_FORMAT1,
83 cff_ENC_FORMAT_SUPPLEMENT,
84 cff_ENC_UNSPECED,
85 };
86
87 typedef struct {
88 cff_Value *stack;
89 cff_Value transient[32];
90 arity_t index;
91 arity_t max;
92 uint8_t stem;
93 } cff_Stack;
94
95 typedef struct {
96 uint8_t *raw_data;
97 uint32_t raw_length;
98 uint16_t cnt_glyph;
99
100 cff_Header head;
101 cff_Index name;
102 cff_Index top_dict;
103 cff_Index string;
104 cff_Index global_subr;
105
106 cff_Encoding encodings; // offset
107 cff_Charset charsets; // offset
108 cff_FDSelect fdselect; // offset
109 cff_Index char_strings; // offset
110 cff_Index font_dict; // offset
111 cff_Index local_subr; // offset
112 } cff_File;
113
114 // Outline builder method table
115 typedef struct {
116 void (*setWidth)(void *context, double width);
117 void (*newContour)(void *context);
118 void (*lineTo)(void *context, double x1, double y1);
119 void (*curveTo)(void *context, double x1, double y1, double x2, double y2, double x3, double y3);
120 void (*setHint)(void *context, bool isVertical, double position, double width);
121 void (*setMask)(void *context, bool isContourMask, bool *mask);
122 double (*getrand)(void *context);
123 } cff_IOutlineBuilder;
124
125 /*
126 CFF -> Compact Font Format
127 CS2 -> Type2 CharString
128 */
129
130 extern const char *op_cff_name(uint32_t op);
131 extern const char *op_cs2_name(uint32_t op);
132 uint8_t cff_getStandardArity(uint32_t op);
133
134 sds sdsget_cff_sid(uint16_t idx, cff_Index str);
135
136 extern uint32_t cff_decodeCffToken(const uint8_t *start, cff_Value *val);
137 extern uint32_t cff_decodeCS2Token(const uint8_t *start, cff_Value *val);
138
139 // number, number, float
140 extern caryll_Buffer *cff_encodeCffOperator(int32_t val);
141 extern caryll_Buffer *cff_encodeCffInteger(int32_t val);
142 extern caryll_Buffer *cff_encodeCffFloat(double val);
143
144 /*
145 Writer
146 */
147
148 extern caryll_Buffer *cff_buildOffset(int32_t val);
149 extern caryll_Buffer *cff_buildHeader(void);
150
151 void cff_mergeCS2Int(caryll_Buffer *blob, int32_t val);
152 void cff_mergeCS2Operator(caryll_Buffer *blob, int32_t val);
153 void cff_mergeCS2Operand(caryll_Buffer *blob, double val);
154 void cff_mergeCS2Special(caryll_Buffer *blob, uint8_t val);
155
156 extern uint8_t cff_parseSubr(uint16_t idx, uint8_t *raw, cff_Index fdarray, cff_FDSelect select, cff_Index *subr);
157 void cff_parseOutline(uint8_t *data, uint32_t len, cff_Index gsubr, cff_Index lsubr, cff_Stack *stack, void *outline,
158 cff_IOutlineBuilder methods, const otfcc_Options *options);
159
160 // File
161 extern cff_File *cff_openStream(uint8_t *data, uint32_t len, const otfcc_Options *options);
162 extern void cff_close(cff_File *file);
163
164 #endif