2 * Copyright © 2023 Behdad Esfahbod
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
35 #ifndef HB_WASM_BEGIN_DECLS
37 # define HB_WASM_BEGIN_DECLS extern "C" {
38 # define HB_WASM_END_DECLS }
39 # else /* !__cplusplus */
40 # define HB_WASM_BEGIN_DECLS
41 # define HB_WASM_END_DECLS
42 # endif /* !__cplusplus */
49 #define HB_WASM_API(ret_t, name) ret_t name
51 #ifndef HB_WASM_API_COMPOUND /* compound return type */
52 #define HB_WASM_API_COMPOUND(ret_t, name) HB_WASM_API(ret_t, name)
54 #ifndef HB_WASM_INTERFACE
55 #define HB_WASM_INTERFACE(ret_t, name) ret_t name
57 #ifndef HB_WASM_EXEC_ENV
58 #define HB_WASM_EXEC_ENV
60 #ifndef HB_WASM_EXEC_ENV_COMPOUND
61 #define HB_WASM_EXEC_ENV_COMPOUND HB_WASM_EXEC_ENV
66 #define bool_t uint32_t
69 #define ptr_t(type_t) type_t *
72 #define ptr_d(type_t, name) type_t *name
75 typedef uint32_t codepoint_t;
76 typedef int32_t position_t;
77 typedef uint32_t mask_t;
78 typedef uint32_t tag_t;
79 #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)))
82 DIRECTION_INVALID = 0,
88 #define DIRECTION_IS_VALID(dir) ((((unsigned int) (dir)) & ~3U) == 4)
89 #define DIRECTION_IS_HORIZONTAL(dir) ((((unsigned int) (dir)) & ~1U) == 4)
90 #define DIRECTION_IS_VERTICAL(dir) ((((unsigned int) (dir)) & ~1U) == 6)
91 #define DIRECTION_IS_FORWARD(dir) ((((unsigned int) (dir)) & ~2U) == 4)
92 #define DIRECTION_IS_BACKWARD(dir) ((((unsigned int) (dir)) & ~2U) == 5)
93 #define DIRECTION_REVERSE(dir) ((direction_t) (((unsigned int) (dir)) ^ 1))
95 typedef tag_t script_t; /* ISO 15924 representation of Unicode scripts. */
100 HB_WASM_API (direction_t, script_get_horizontal_direction) (HB_WASM_EXEC_ENV
111 #define BLOB_INIT {0, 0}
113 HB_WASM_API (void, blob_free) (HB_WASM_EXEC_ENV
114 ptr_d(blob_t, blob));
129 position_t x_advance;
130 position_t y_advance;
139 ptr_t(glyph_info_t) info;
140 ptr_t(glyph_position_t) pos;
142 #define BUFFER_CONTENTS_INIT {0, 0, 0}
144 HB_WASM_API (bool_t, buffer_contents_realloc) (HB_WASM_EXEC_ENV
145 ptr_d(buffer_contents_t, contents),
148 HB_WASM_API (void, buffer_contents_free) (HB_WASM_EXEC_ENV
149 ptr_d(buffer_contents_t, contents));
151 typedef struct buffer_t buffer_t;
153 HB_WASM_API (bool_t, buffer_copy_contents) (HB_WASM_EXEC_ENV
154 ptr_d(buffer_t, buffer),
155 ptr_d(buffer_contents_t, contents));
157 HB_WASM_API (bool_t, buffer_set_contents) (HB_WASM_EXEC_ENV
158 ptr_d(buffer_t, buffer),
159 ptr_d(const buffer_contents_t, contents));
161 HB_WASM_API (direction_t, buffer_get_direction) (HB_WASM_EXEC_ENV
162 ptr_d(buffer_t, buffer));
164 HB_WASM_API (script_t, buffer_get_script) (HB_WASM_EXEC_ENV
165 ptr_d(buffer_t, buffer));
167 HB_WASM_API (void, buffer_reverse) (HB_WASM_EXEC_ENV
168 ptr_d(buffer_t, buffer));
170 HB_WASM_API (void, buffer_reverse_clusters) (HB_WASM_EXEC_ENV
171 ptr_d(buffer_t, buffer));
175 typedef struct face_t face_t;
177 HB_WASM_API (ptr_t(face_t), face_create) (HB_WASM_EXEC_ENV
181 HB_WASM_API (bool_t, face_copy_table) (HB_WASM_EXEC_ENV
184 ptr_d(blob_t, blob));
186 HB_WASM_API (unsigned, face_get_upem) (HB_WASM_EXEC_ENV
187 ptr_d(face_t, face));
191 typedef struct font_t font_t;
193 HB_WASM_API (ptr_t(font_t), font_create) (HB_WASM_EXEC_ENV
194 ptr_d(face_t, face));
196 HB_WASM_API (ptr_t(face_t), font_get_face) (HB_WASM_EXEC_ENV
197 ptr_d(font_t, font));
199 HB_WASM_API (void, font_get_scale) (HB_WASM_EXEC_ENV
201 ptr_d(int32_t, x_scale),
202 ptr_d(int32_t, y_scale));
204 HB_WASM_API (codepoint_t, font_get_glyph) (HB_WASM_EXEC_ENV
207 codepoint_t variation_selector);
209 HB_WASM_API (position_t, font_get_glyph_h_advance) (HB_WASM_EXEC_ENV
213 HB_WASM_API (position_t, font_get_glyph_v_advance) (HB_WASM_EXEC_ENV
219 position_t x_bearing;
220 position_t y_bearing;
225 HB_WASM_API (bool_t, font_get_glyph_extents) (HB_WASM_EXEC_ENV
228 ptr_d(glyph_extents_t, extents));
230 HB_WASM_API (void, font_glyph_to_string) (HB_WASM_EXEC_ENV
233 char *s, uint32_t size);
242 HB_WASM_API (bool_t, font_copy_coords) (HB_WASM_EXEC_ENV
244 ptr_d(coords_t, coords));
246 HB_WASM_API (bool_t, font_set_coords) (HB_WASM_EXEC_ENV
248 ptr_d(coords_t, coords));
252 enum glyph_outline_point_type_t
265 } glyph_outline_point_t;
270 ptr_t(glyph_outline_point_t) points;
272 ptr_t(uint32_t) contours;
274 #define GLYPH_OUTLINE_INIT {0, 0, 0, 0}
276 HB_WASM_API (void, glyph_outline_free) (HB_WASM_EXEC_ENV
277 ptr_d(glyph_outline_t, outline));
279 HB_WASM_API (bool_t, font_copy_glyph_outline) (HB_WASM_EXEC_ENV
282 ptr_d(glyph_outline_t, outline));
294 #define FEATURE_GLOBAL_START 0
295 #define FEATURE_GLOBAL_END ((uint32_t) -1)
297 HB_WASM_API (bool_t, shape_with) (HB_WASM_EXEC_ENV
299 ptr_d(buffer_t, buffer),
300 ptr_d(const feature_t, features),
301 uint32_t num_features,
304 /* Implement these in your shaper. */
306 HB_WASM_INTERFACE (ptr_t(void), shape_plan_create) (ptr_d(face_t, face));
308 HB_WASM_INTERFACE (bool_t, shape) (ptr_d(void, shape_plan),
310 ptr_d(buffer_t, buffer),
311 ptr_d(const feature_t, features),
312 uint32_t num_features);
314 HB_WASM_INTERFACE (void, shape_plan_destroy) (ptr_d(void, shape_plan));
319 #endif /* HB_WASM_API_H */