blob: 5db45c74cbb80fcae0262983440fc74c5b54c58d [file] [log] [blame]
Behdad Esfahbod98070642023-02-23 10:58:22 -07001/*
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
Behdad Esfahbod98070642023-02-23 10:58:22 -070030
31#ifdef HB_DEBUG_WASM
32namespace hb { namespace wasm {
Behdad Esfahbodd7a66712023-02-23 13:16:49 -070033
34static void debugprint (HB_WASM_EXEC_ENV char *str)
35{ DEBUG_MSG (WASM, exec_env, "%s", str); }
36static void debugprint1 (HB_WASM_EXEC_ENV char *str, int32_t i1)
37{ DEBUG_MSG (WASM, exec_env, "%s: %d", str, i1); }
38static 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); }
40static 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); }
42static 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
Behdad Esfahbod98070642023-02-23 10:58:22 -070045}}
46#endif
47
48#define NATIVE_SYMBOL(signature, name) {#name, (void *) hb::wasm::name, signature, NULL}
Behdad Esfahbodb6c18142023-03-03 11:31:08 -070049/* Note: the array must be static defined since runtime will keep it after registration.
50 * Also not const, because it modifies it (sorts it).
Behdad Esfahbod7df9b3d2023-02-26 14:54:07 -070051 * https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md
52 *
53 * TODO Allocate this lazily in _hb_wasm_init(). */
Behdad Esfahbod98070642023-02-23 10:58:22 -070054static NativeSymbol _hb_wasm_native_symbols[] =
55{
Behdad Esfahbodec3270c2023-02-24 13:31:10 -070056 /* common */
57 NATIVE_SYMBOL ("(i)i", script_get_horizontal_direction),
Behdad Esfahbod98070642023-02-23 10:58:22 -070058
Behdad Esfahbodcbd5c552023-02-23 14:54:46 -070059 /* blob */
60 NATIVE_SYMBOL ("(i)", blob_free),
61
Behdad Esfahbod5cecfe82023-02-23 13:58:40 -070062 /* buffer */
Behdad Esfahbod851ef132023-02-23 15:06:18 -070063 NATIVE_SYMBOL ("(i)", buffer_contents_free),
Behdad Esfahbod16ecb962023-02-24 19:53:47 -070064 NATIVE_SYMBOL ("(ii)i", buffer_contents_realloc),
Behdad Esfahbodb5b577f2023-02-25 08:12:16 -070065 NATIVE_SYMBOL ("(ii)i", buffer_copy_contents),
Behdad Esfahbodc1dc1122023-02-23 15:47:56 -070066 NATIVE_SYMBOL ("(ii)i", buffer_set_contents),
Behdad Esfahbod0a51ed32023-02-24 10:07:59 -070067 NATIVE_SYMBOL ("(i)i", buffer_get_direction),
Behdad Esfahbodec3270c2023-02-24 13:31:10 -070068 NATIVE_SYMBOL ("(i)i", buffer_get_script),
Behdad Esfahbodb3b6e8d2023-02-24 12:03:53 -070069 NATIVE_SYMBOL ("(i)", buffer_reverse),
Behdad Esfahboda08dbf42023-02-24 10:13:21 -070070 NATIVE_SYMBOL ("(i)", buffer_reverse_clusters),
Behdad Esfahbod5cecfe82023-02-23 13:58:40 -070071
Behdad Esfahbode87b1b32023-02-23 12:23:52 -070072 /* face */
Behdad Esfahbod2663a9b2023-03-31 17:38:23 -060073 NATIVE_SYMBOL ("(ii)i", face_create),
Behdad Esfahbod20045282023-02-25 08:23:14 -070074 NATIVE_SYMBOL ("(iii)i", face_copy_table),
Behdad Esfahbod149199e2023-02-24 09:39:25 -070075 NATIVE_SYMBOL ("(i)i", face_get_upem),
Behdad Esfahbode87b1b32023-02-23 12:23:52 -070076
Behdad Esfahbod98070642023-02-23 10:58:22 -070077 /* font */
Behdad Esfahbod2663a9b2023-03-31 17:38:23 -060078 NATIVE_SYMBOL ("(i)i", font_create),
Behdad Esfahbodc1dc1122023-02-23 15:47:56 -070079 NATIVE_SYMBOL ("(i)i", font_get_face),
Behdad Esfahbod23b58b52023-02-24 09:50:34 -070080 NATIVE_SYMBOL ("(iii)", font_get_scale),
Simon Cozense0fec1d2023-02-23 22:18:22 +000081 NATIVE_SYMBOL ("(iii)i", font_get_glyph),
Behdad Esfahbodc1dc1122023-02-23 15:47:56 -070082 NATIVE_SYMBOL ("(ii)i", font_get_glyph_h_advance),
83 NATIVE_SYMBOL ("(ii)i", font_get_glyph_v_advance),
Behdad Esfahbodfe557e22023-02-24 12:20:31 -070084 NATIVE_SYMBOL ("(iii)i", font_get_glyph_extents),
Behdad Esfahbod1acff902023-02-24 11:53:47 -070085 NATIVE_SYMBOL ("(ii$*)", font_glyph_to_string),
Behdad Esfahbod65966e02023-02-25 08:59:03 -070086 NATIVE_SYMBOL ("(iii)i", font_copy_glyph_outline),
Simon Cozens85a1fdd2023-03-27 14:42:21 +010087 NATIVE_SYMBOL ("(ii)i", font_copy_coords),
88 NATIVE_SYMBOL ("(ii)i", font_set_coords),
Behdad Esfahbod98070642023-02-23 10:58:22 -070089
Behdad Esfahbod918df8c2023-02-25 10:29:03 -070090 /* outline */
91 NATIVE_SYMBOL ("(i)", glyph_outline_free),
92
Behdad Esfahbod2bde2f62023-02-24 11:03:13 -070093 /* shape */
Behdad Esfahbod9f8ad392023-02-24 14:16:11 -070094 NATIVE_SYMBOL ("(iiii$)i", shape_with),
Behdad Esfahbod2bde2f62023-02-24 11:03:13 -070095
Behdad Esfahbod98070642023-02-23 10:58:22 -070096 /* debug */
97#ifdef HB_DEBUG_WASM
98 NATIVE_SYMBOL ("($)", debugprint),
Behdad Esfahbodd7a66712023-02-23 13:16:49 -070099 NATIVE_SYMBOL ("($i)", debugprint1),
100 NATIVE_SYMBOL ("($ii)", debugprint2),
101 NATIVE_SYMBOL ("($iii)", debugprint3),
102 NATIVE_SYMBOL ("($iiii)", debugprint4),
Behdad Esfahbod98070642023-02-23 10:58:22 -0700103#endif
104
105};
106#undef NATIVE_SYMBOL
107
108
109#endif /* HB_WASM_API_LIST_HH */