[wasm-api] Change face_copy_table to return success

This commit is contained in:
Behdad Esfahbod 2023-02-25 08:23:14 -07:00
parent 83b9c34f0b
commit 2004528cf8
5 changed files with 32 additions and 15 deletions

View File

@ -31,22 +31,33 @@ namespace hb {
namespace wasm {
HB_WASM_API_COMPOUND (blob_t, face_copy_table) (HB_WASM_EXEC_ENV_COMPOUND
ptr_d(face_t, face),
tag_t table_tag)
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_RETURN_STRUCT (blob_t, ret);
HB_REF2OBJ (face);
HB_PTR_PARAM (blob_t, blob);
if (unlikely (!blob))
return false;
hb_blob_t *blob = hb_face_reference_table (face, table_tag);
hb_blob_t *hb_blob = hb_face_reference_table (face, table_tag);
unsigned length;
const char *data = hb_blob_get_data (blob, &length);
const char *data = hb_blob_get_data (hb_blob, &length);
ret.length = length;
ret.data = wasm_runtime_module_dup_data (module_inst, data, length);
blob->length = length;
blob->data = wasm_runtime_module_dup_data (module_inst, data, length);
hb_blob_destroy (blob);
hb_blob_destroy (hb_blob);
if (blob->length && !blob->data)
{
blob->length = 0;
return false;
}
return true;
}
HB_WASM_API (unsigned, face_get_upem) (HB_WASM_EXEC_ENV

View File

@ -67,7 +67,7 @@ static NativeSymbol _hb_wasm_native_symbols[] =
NATIVE_SYMBOL ("(i)", buffer_reverse_clusters),
/* face */
NATIVE_SYMBOL ("(iii)", face_copy_table),
NATIVE_SYMBOL ("(iii)i", face_copy_table),
NATIVE_SYMBOL ("(i)i", face_get_upem),
/* font */

View File

@ -173,9 +173,10 @@ HB_WASM_API (void, buffer_reverse_clusters) (HB_WASM_EXEC_ENV
typedef struct face_t face_t;
HB_WASM_API_COMPOUND (blob_t, face_copy_table) (HB_WASM_EXEC_ENV_COMPOUND
ptr_d(face_t, face),
tag_t table_tag);
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));

View File

@ -21,7 +21,9 @@ uint32_t heap_size = 2 * 1024 * 1024;
static const void *copy_table (const void *data, unsigned int tag, size_t *len)
{
face_t *face = (face_t *) data;
blob_t blob = face_copy_table (face, tag);
blob_t blob;
if (!face_copy_table (face, tag, &blob))
abort ();
*len = blob.length;
return blob.data;

View File

@ -3,6 +3,7 @@
#include <hb-wasm-api.h>
extern "C" {
void abort ();
void debugprint (const char *s);
void debugprint1 (const char *s, int32_t);
void debugprint2 (const char *s, int32_t, int32_t);
@ -17,7 +18,9 @@ shape (void *shape_plan,
{
face_t *face = font_get_face (font);
blob_t blob = face_copy_table (face, TAG ('c','m','a','p'));
blob_t blob;
if (!face_copy_table (face, TAG ('c','m','a','p'), &blob))
abort ();
debugprint1 ("cmap length", blob.length);