mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-28 00:59:16 +01:00
Add WASM API to wrap features
This commit is contained in:
1 parent
1b0cd494ea
commit
40524f2162
3 files changed
+63
No files matched your search
@@ -93,6 +93,8 @@ static NativeSymbol _hb_wasm_native_symbols[] =
|
||||
|
||||
/* shape */
|
||||
NATIVE_SYMBOL ("(iiii$)i", shape_with),
|
||||
NATIVE_SYMBOL ("(iii)i", feature_copy_contents),
|
||||
NATIVE_SYMBOL ("(i)", features_free),
|
||||
|
||||
/* debug */
|
||||
#ifdef HB_DEBUG_WASM
|
||||
|
||||
@@ -64,6 +64,52 @@ HB_WASM_INTERFACE (bool_t, shape_with) (HB_WASM_EXEC_ENV
|
||||
shaper_list);
|
||||
}
|
||||
|
||||
HB_WASM_API (bool_t, feature_copy_contents) (HB_WASM_EXEC_ENV
|
||||
ptr_d(const feature_t, features),
|
||||
uint32_t num_features,
|
||||
ptr_d(features_t, output))
|
||||
{
|
||||
HB_PTR_PARAM (features_t, output);
|
||||
if (unlikely (!output))
|
||||
return false;
|
||||
|
||||
unsigned bytes;
|
||||
if (unlikely (hb_unsigned_mul_overflows (num_features, sizeof (feature_t), &bytes)))
|
||||
return false;
|
||||
|
||||
if (!num_features)
|
||||
{
|
||||
output->length = 0;
|
||||
output->features = nullref;
|
||||
return true;
|
||||
}
|
||||
|
||||
HB_ARRAY_PARAM (const feature_t, features, num_features);
|
||||
if (unlikely (!features))
|
||||
return false;
|
||||
|
||||
feature_t *dst = nullptr;
|
||||
uint32_t dstref = module_malloc (bytes, (void **) &dst);
|
||||
if (unlikely (!dstref))
|
||||
return false;
|
||||
|
||||
hb_memcpy (dst, features, bytes);
|
||||
output->length = num_features;
|
||||
output->features = dstref;
|
||||
return true;
|
||||
}
|
||||
|
||||
HB_WASM_API (void, features_free) (HB_WASM_EXEC_ENV
|
||||
ptr_d(features_t, features))
|
||||
{
|
||||
HB_PTR_PARAM (features_t, features);
|
||||
if (unlikely (!features))
|
||||
return;
|
||||
|
||||
module_free (features->features);
|
||||
features->features = nullref;
|
||||
features->length = 0;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
|
||||
@@ -303,6 +303,21 @@ typedef struct
|
||||
#define FEATURE_GLOBAL_START 0
|
||||
#define FEATURE_GLOBAL_END ((uint32_t) -1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t length;
|
||||
ptr_t(feature_t) features;
|
||||
} features_t;
|
||||
#define FEATURES_INIT {0, 0}
|
||||
|
||||
HB_WASM_API (bool_t, feature_copy_contents) (HB_WASM_EXEC_ENV
|
||||
ptr_d(const feature_t, features),
|
||||
uint32_t num_features,
|
||||
ptr_d(features_t, output));
|
||||
|
||||
HB_WASM_API (void, features_free) (HB_WASM_EXEC_ENV
|
||||
ptr_d(features_t, features));
|
||||
|
||||
HB_WASM_API (bool_t, shape_with) (HB_WASM_EXEC_ENV
|
||||
ptr_d(font_t, font),
|
||||
ptr_d(buffer_t, buffer),
|
||||
|
||||
Reference in new issue
Block a user