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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
/*
* Copyright © 2023 Behdad Esfahbod
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
#ifndef HB_WASM_API_H
#define HB_WASM_API_H
/*
#include "hb.h"
*/
#include <stdint.h>
#ifndef HB_WASM_BEGIN_DECLS
# ifdef __cplusplus
# define HB_WASM_BEGIN_DECLS extern "C" {
# define HB_WASM_END_DECLS }
# else /* !__cplusplus */
# define HB_WASM_BEGIN_DECLS
# define HB_WASM_END_DECLS
# endif /* !__cplusplus */
#endif
HB_WASM_BEGIN_DECLS
#ifndef HB_WASM_API
#define HB_WASM_API(ret_t, name) ret_t name
#endif
#ifndef HB_WASM_API_COMPOUND /* compound return type */
#define HB_WASM_API_COMPOUND(ret_t, name) HB_WASM_API(ret_t, name)
#endif
#ifndef HB_WASM_INTERFACE
#define HB_WASM_INTERFACE(ret_t, name) ret_t name
#endif
#ifndef HB_WASM_EXEC_ENV
#define HB_WASM_EXEC_ENV
#endif
#ifndef HB_WASM_EXEC_ENV_COMPOUND
#define HB_WASM_EXEC_ENV_COMPOUND HB_WASM_EXEC_ENV
#endif
#ifndef bool_t
#define bool_t uint32_t
#endif
#ifndef ptr_t
#define ptr_t(type_t) type_t *
#endif
#ifndef ptr_d
#define ptr_d(type_t, name) type_t *name
#endif
typedef uint32_t codepoint_t;
typedef int32_t position_t;
typedef uint32_t mask_t;
typedef uint32_t tag_t;
#define TAG(c1,c2,c3,c4) ((tag_t)((((uint32_t)(c1)&0xFF)<<24)|(((uint32_t)(c2)&0xFF)<<16)|(((uint32_t)(c3)&0xFF)<<8)|((uint32_t)(c4)&0xFF)))
typedef enum {
DIRECTION_INVALID = 0,
DIRECTION_LTR = 4,
DIRECTION_RTL,
DIRECTION_TTB,
DIRECTION_BTT
} direction_t;
#define DIRECTION_IS_VALID(dir) ((((unsigned int) (dir)) & ~3U) == 4)
#define DIRECTION_IS_HORIZONTAL(dir) ((((unsigned int) (dir)) & ~1U) == 4)
#define DIRECTION_IS_VERTICAL(dir) ((((unsigned int) (dir)) & ~1U) == 6)
#define DIRECTION_IS_FORWARD(dir) ((((unsigned int) (dir)) & ~2U) == 4)
#define DIRECTION_IS_BACKWARD(dir) ((((unsigned int) (dir)) & ~2U) == 5)
#define DIRECTION_REVERSE(dir) ((direction_t) (((unsigned int) (dir)) ^ 1))
typedef tag_t script_t; /* ISO 15924 representation of Unicode scripts. */
/* common */
HB_WASM_API (direction_t, script_get_horizontal_direction) (HB_WASM_EXEC_ENV
script_t script);
/* blob */
typedef struct
{
uint32_t length;
ptr_t(char) data;
} blob_t;
#define BLOB_INIT {0, 0}
HB_WASM_API (void, blob_free) (HB_WASM_EXEC_ENV
ptr_d(blob_t, blob));
/* buffer */
typedef struct
{
uint32_t codepoint;
uint32_t mask;
uint32_t cluster;
uint32_t var1;
uint32_t var2;
} glyph_info_t;
typedef struct
{
position_t x_advance;
position_t y_advance;
position_t x_offset;
position_t y_offset;
uint32_t var;
} glyph_position_t;
typedef struct
{
uint32_t length;
ptr_t(glyph_info_t) info;
ptr_t(glyph_position_t) pos;
} buffer_contents_t;
#define BUFFER_CONTENTS_INIT {0, 0, 0}
HB_WASM_API (bool_t, buffer_contents_realloc) (HB_WASM_EXEC_ENV
ptr_d(buffer_contents_t, contents),
uint32_t size);
HB_WASM_API (void, buffer_contents_free) (HB_WASM_EXEC_ENV
ptr_d(buffer_contents_t, contents));
typedef struct buffer_t buffer_t;
HB_WASM_API (bool_t, buffer_copy_contents) (HB_WASM_EXEC_ENV
ptr_d(buffer_t, buffer),
ptr_d(buffer_contents_t, contents));
HB_WASM_API (bool_t, buffer_set_contents) (HB_WASM_EXEC_ENV
ptr_d(buffer_t, buffer),
ptr_d(const buffer_contents_t, contents));
HB_WASM_API (direction_t, buffer_get_direction) (HB_WASM_EXEC_ENV
ptr_d(buffer_t, buffer));
HB_WASM_API (script_t, buffer_get_script) (HB_WASM_EXEC_ENV
ptr_d(buffer_t, buffer));
HB_WASM_API (void, buffer_reverse) (HB_WASM_EXEC_ENV
ptr_d(buffer_t, buffer));
HB_WASM_API (void, buffer_reverse_clusters) (HB_WASM_EXEC_ENV
ptr_d(buffer_t, buffer));
/* face */
typedef struct face_t face_t;
HB_WASM_API (ptr_t(face_t), face_create) (HB_WASM_EXEC_ENV
ptr_d(blob_t, blob),
unsigned int);
HB_WASM_API (bool_t, face_copy_table) (HB_WASM_EXEC_ENV
ptr_d(face_t, face),
tag_t table_tag,
ptr_d(blob_t, blob));
HB_WASM_API (unsigned, face_get_upem) (HB_WASM_EXEC_ENV
ptr_d(face_t, face));
/* font */
typedef struct font_t font_t;
HB_WASM_API (ptr_t(font_t), font_create) (HB_WASM_EXEC_ENV
ptr_d(face_t, face));
HB_WASM_API (ptr_t(face_t), font_get_face) (HB_WASM_EXEC_ENV
ptr_d(font_t, font));
HB_WASM_API (void, font_get_scale) (HB_WASM_EXEC_ENV
ptr_d(font_t, font),
ptr_d(int32_t, x_scale),
ptr_d(int32_t, y_scale));
HB_WASM_API (codepoint_t, font_get_glyph) (HB_WASM_EXEC_ENV
ptr_d(font_t, font),
codepoint_t unicode,
codepoint_t variation_selector);
HB_WASM_API (position_t, font_get_glyph_h_advance) (HB_WASM_EXEC_ENV
ptr_d(font_t, font),
codepoint_t glyph);
HB_WASM_API (position_t, font_get_glyph_v_advance) (HB_WASM_EXEC_ENV
ptr_d(font_t, font),
codepoint_t glyph);
typedef struct
{
position_t x_bearing;
position_t y_bearing;
position_t width;
position_t height;
} glyph_extents_t;
HB_WASM_API (bool_t, font_get_glyph_extents) (HB_WASM_EXEC_ENV
ptr_d(font_t, font),
codepoint_t glyph,
ptr_d(glyph_extents_t, extents));
HB_WASM_API (void, font_glyph_to_string) (HB_WASM_EXEC_ENV
ptr_d(font_t, font),
codepoint_t glyph,
char *s, uint32_t size);
typedef struct
{
unsigned int length;
ptr_t(int) coords;
} coords_t;
HB_WASM_API (bool_t, font_copy_coords) (HB_WASM_EXEC_ENV
ptr_d(font_t, font),
ptr_d(coords_t, coords));
HB_WASM_API (bool_t, font_set_coords) (HB_WASM_EXEC_ENV
ptr_d(font_t, font),
ptr_d(coords_t, coords));
/* outline */
enum glyph_outline_point_type_t
{
MOVE_TO,
LINE_TO,
QUADRATIC_TO,
CUBIC_TO,
};
typedef struct
{
float x;
float y;
uint32_t type;
} glyph_outline_point_t;
typedef struct
{
uint32_t n_points;
ptr_t(glyph_outline_point_t) points;
uint32_t n_contours;
ptr_t(uint32_t) contours;
} glyph_outline_t;
#define GLYPH_OUTLINE_INIT {0, 0, 0, 0}
HB_WASM_API (void, glyph_outline_free) (HB_WASM_EXEC_ENV
ptr_d(glyph_outline_t, outline));
HB_WASM_API (bool_t, font_copy_glyph_outline) (HB_WASM_EXEC_ENV
ptr_d(font_t, font),
codepoint_t glyph,
ptr_d(glyph_outline_t, outline));
/* shape */
typedef struct
{
tag_t tag;
uint32_t value;
uint32_t start;
uint32_t end;
} feature_t;
#define FEATURE_GLOBAL_START 0
#define FEATURE_GLOBAL_END ((uint32_t) -1)
HB_WASM_API (bool_t, shape_with) (HB_WASM_EXEC_ENV
ptr_d(font_t, font),
ptr_d(buffer_t, buffer),
ptr_d(const feature_t, features),
uint32_t num_features,
const char *shaper);
/* Implement these in your shaper. */
HB_WASM_INTERFACE (ptr_t(void), shape_plan_create) (ptr_d(face_t, face));
HB_WASM_INTERFACE (bool_t, shape) (ptr_d(void, shape_plan),
ptr_d(font_t, font),
ptr_d(buffer_t, buffer),
ptr_d(const feature_t, features),
uint32_t num_features);
HB_WASM_INTERFACE (void, shape_plan_destroy) (ptr_d(void, shape_plan));
HB_WASM_END_DECLS
#endif /* HB_WASM_API_H */
|