xref: /aosp_15_r20/external/harfbuzz_ng/src/hb-wasm-api-list.hh (revision 2d1272b857b1f7575e6e246373e1cb218663db8a)
1 /*
2  * Copyright © 2023  Behdad Esfahbod
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
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.
11  *
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
16  * DAMAGE.
17  *
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.
23  */
24 
25 #ifndef HB_WASM_API_LIST_HH
26 #define HB_WASM_API_LIST_HH
27 
28 #include "hb-wasm-api.hh"
29 
30 
31 #ifdef HB_DEBUG_WASM
32 namespace hb { namespace wasm {
33 
debugprint(HB_WASM_EXEC_ENV char * str)34 static void debugprint (HB_WASM_EXEC_ENV char *str)
35 { DEBUG_MSG (WASM, exec_env, "%s", str); }
debugprint1(HB_WASM_EXEC_ENV char * str,int32_t i1)36 static void debugprint1 (HB_WASM_EXEC_ENV char *str, int32_t i1)
37 { DEBUG_MSG (WASM, exec_env, "%s: %d", str, i1); }
debugprint2(HB_WASM_EXEC_ENV char * str,int32_t i1,int32_t i2)38 static void debugprint2 (HB_WASM_EXEC_ENV char *str, int32_t i1, int32_t i2)
39 { DEBUG_MSG (WASM, exec_env, "%s: %d, %d", str, i1, i2); }
debugprint3(HB_WASM_EXEC_ENV char * str,int32_t i1,int32_t i2,int32_t i3)40 static void debugprint3 (HB_WASM_EXEC_ENV char *str, int32_t i1, int32_t i2, int32_t i3)
41 { DEBUG_MSG (WASM, exec_env, "%s: %d, %d, %d", str, i1, i2, i3); }
debugprint4(HB_WASM_EXEC_ENV char * str,int32_t i1,int32_t i2,int32_t i3,int32_t i4)42 static void debugprint4 (HB_WASM_EXEC_ENV char *str, int32_t i1, int32_t i2, int32_t i3, int32_t i4)
43 { DEBUG_MSG (WASM, exec_env, "%s: %d, %d, %d, %d", str, i1, i2, i3, i4); }
44 
45 }}
46 #endif
47 
48 #define NATIVE_SYMBOL(signature, name) {#name, (void *) hb::wasm::name, signature, NULL}
49 /* Note: the array must be static defined since runtime will keep it after registration.
50  * Also not const, because it modifies it (sorts it).
51  * https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md
52  *
53  * TODO Allocate this lazily in _hb_wasm_init(). */
54 static NativeSymbol _hb_wasm_native_symbols[] =
55 {
56   /* common */
57   NATIVE_SYMBOL ("(i)i",	script_get_horizontal_direction),
58 
59   /* blob */
60   NATIVE_SYMBOL ("(i)",		blob_free),
61 
62   /* buffer */
63   NATIVE_SYMBOL ("(i)",		buffer_contents_free),
64   NATIVE_SYMBOL ("(ii)i",	buffer_contents_realloc),
65   NATIVE_SYMBOL ("(ii)i",	buffer_copy_contents),
66   NATIVE_SYMBOL ("(ii)i",	buffer_set_contents),
67   NATIVE_SYMBOL ("(i)i",	buffer_get_direction),
68   NATIVE_SYMBOL ("(i)i",	buffer_get_script),
69   NATIVE_SYMBOL ("(i)",		buffer_reverse),
70   NATIVE_SYMBOL ("(i)",		buffer_reverse_clusters),
71 
72   /* face */
73   NATIVE_SYMBOL ("(ii)i",	face_create),
74   NATIVE_SYMBOL ("(iii)i",	face_copy_table),
75   NATIVE_SYMBOL ("(i)i",	face_get_upem),
76 
77   /* font */
78   NATIVE_SYMBOL ("(i)i",	font_create),
79   NATIVE_SYMBOL ("(i)i",	font_get_face),
80   NATIVE_SYMBOL ("(iii)",	font_get_scale),
81   NATIVE_SYMBOL ("(iii)i",	font_get_glyph),
82   NATIVE_SYMBOL ("(ii)i",	font_get_glyph_h_advance),
83   NATIVE_SYMBOL ("(ii)i",	font_get_glyph_v_advance),
84   NATIVE_SYMBOL ("(iii)i",	font_get_glyph_extents),
85   NATIVE_SYMBOL ("(ii$*)",	font_glyph_to_string),
86   NATIVE_SYMBOL ("(iii)i",	font_copy_glyph_outline),
87   NATIVE_SYMBOL ("(ii)i",	font_copy_coords),
88   NATIVE_SYMBOL ("(ii)i",	font_set_coords),
89 
90   /* outline */
91   NATIVE_SYMBOL ("(i)",		glyph_outline_free),
92 
93   /* shape */
94   NATIVE_SYMBOL ("(iiii$)i",	shape_with),
95 
96   /* debug */
97 #ifdef HB_DEBUG_WASM
98   NATIVE_SYMBOL ("($)",		debugprint),
99   NATIVE_SYMBOL ("($i)",	debugprint1),
100   NATIVE_SYMBOL ("($ii)",	debugprint2),
101   NATIVE_SYMBOL ("($iii)",	debugprint3),
102   NATIVE_SYMBOL ("($iiii)",	debugprint4),
103 #endif
104 
105 };
106 #undef NATIVE_SYMBOL
107 
108 
109 #endif /* HB_WASM_API_LIST_HH */
110