[wasm-api] Bind buffer_set_contents
This commit is contained in:
parent
e0fec1dda0
commit
c1dc112121
|
@ -493,6 +493,13 @@ struct hb_buffer_t
|
||||||
|
|
||||||
HB_NODISCARD HB_INTERNAL bool enlarge (unsigned int size);
|
HB_NODISCARD HB_INTERNAL bool enlarge (unsigned int size);
|
||||||
|
|
||||||
|
HB_NODISCARD bool resize (unsigned length)
|
||||||
|
{
|
||||||
|
assert (!have_output);
|
||||||
|
if (unlikely (!ensure (length))) return false;
|
||||||
|
len = length;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
HB_NODISCARD bool ensure (unsigned int size)
|
HB_NODISCARD bool ensure (unsigned int size)
|
||||||
{ return likely (!size || size < allocated) ? true : enlarge (size); }
|
{ return likely (!size || size < allocated) ? true : enlarge (size); }
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
namespace hb {
|
namespace hb {
|
||||||
namespace wasm {
|
namespace wasm {
|
||||||
|
|
||||||
|
static_assert (sizeof (glyph_info_t) == sizeof (hb_glyph_info_t), "");
|
||||||
|
static_assert (sizeof (glyph_position_t) == sizeof (hb_glyph_position_t), "");
|
||||||
|
|
||||||
void
|
void
|
||||||
buffer_contents_free (HB_WASM_EXEC_ENV
|
buffer_contents_free (HB_WASM_EXEC_ENV
|
||||||
|
@ -59,9 +61,6 @@ buffer_copy_contents (HB_WASM_EXEC_ENV_COMPOUND
|
||||||
if (buffer->have_output)
|
if (buffer->have_output)
|
||||||
buffer->sync ();
|
buffer->sync ();
|
||||||
|
|
||||||
static_assert (sizeof (glyph_info_t) == sizeof (hb_glyph_info_t), "");
|
|
||||||
static_assert (sizeof (glyph_position_t) == sizeof (hb_glyph_position_t), "");
|
|
||||||
|
|
||||||
unsigned length = buffer->len;
|
unsigned length = buffer->len;
|
||||||
ret.length = length;
|
ret.length = length;
|
||||||
ret.info = wasm_runtime_module_dup_data (module_inst, (const char *) buffer->info, length * sizeof (buffer->info[0]));
|
ret.info = wasm_runtime_module_dup_data (module_inst, (const char *) buffer->info, length * sizeof (buffer->info[0]));
|
||||||
|
@ -69,6 +68,35 @@ buffer_copy_contents (HB_WASM_EXEC_ENV_COMPOUND
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool_t
|
||||||
|
buffer_set_contents (HB_WASM_EXEC_ENV
|
||||||
|
ptr_t(buffer_t) bufferref,
|
||||||
|
ptr_t(const buffer_contents_t) contentsptr)
|
||||||
|
{
|
||||||
|
HB_REF2OBJ (buffer);
|
||||||
|
HB_STRUCT_TYPE (buffer_contents_t, contents);
|
||||||
|
if (unlikely (!contents))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
unsigned length = contents->length;
|
||||||
|
unsigned bytes;
|
||||||
|
if (unlikely (hb_unsigned_mul_overflows (length, sizeof (buffer->info[0]), &bytes)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (unlikely (!buffer->resize (length)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
glyph_info_t *info = (glyph_info_t *) (validate_app_addr (contents->info, bytes) ? addr_app_to_native (contents->info) : nullptr);
|
||||||
|
glyph_position_t *pos = (glyph_position_t *) (validate_app_addr (contents->pos, bytes) ? addr_app_to_native (contents->pos) : nullptr);
|
||||||
|
|
||||||
|
buffer->clear_positions (); /* This is wasteful, but we need it to set have_positions=true. */
|
||||||
|
memcpy (buffer->info, info, bytes);
|
||||||
|
memcpy (buffer->pos, pos, bytes);
|
||||||
|
buffer->len = length;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
#endif /* HB_WASM_API_BUFFER_HH */
|
#endif /* HB_WASM_API_BUFFER_HH */
|
||||||
|
|
|
@ -57,15 +57,16 @@ static NativeSymbol _hb_wasm_native_symbols[] =
|
||||||
/* buffer */
|
/* buffer */
|
||||||
NATIVE_SYMBOL ("(i)", buffer_contents_free),
|
NATIVE_SYMBOL ("(i)", buffer_contents_free),
|
||||||
NATIVE_SYMBOL ("(ii)", buffer_copy_contents),
|
NATIVE_SYMBOL ("(ii)", buffer_copy_contents),
|
||||||
|
NATIVE_SYMBOL ("(ii)i", buffer_set_contents),
|
||||||
|
|
||||||
/* face */
|
/* face */
|
||||||
NATIVE_SYMBOL ("(iii)", face_reference_table),
|
NATIVE_SYMBOL ("(iii)", face_reference_table),
|
||||||
|
|
||||||
/* font */
|
/* font */
|
||||||
NATIVE_SYMBOL ("(i)i", font_get_face),
|
NATIVE_SYMBOL ("(i)i", font_get_face),
|
||||||
NATIVE_SYMBOL ("(iii)i", font_get_glyph),
|
NATIVE_SYMBOL ("(iii)i", font_get_glyph),
|
||||||
NATIVE_SYMBOL ("(ii)i", font_get_glyph_h_advance),
|
NATIVE_SYMBOL ("(ii)i", font_get_glyph_h_advance),
|
||||||
NATIVE_SYMBOL ("(ii)i", font_get_glyph_v_advance),
|
NATIVE_SYMBOL ("(ii)i", font_get_glyph_v_advance),
|
||||||
|
|
||||||
/* debug */
|
/* debug */
|
||||||
#ifdef HB_DEBUG_WASM
|
#ifdef HB_DEBUG_WASM
|
||||||
|
|
|
@ -123,6 +123,10 @@ typedef struct buffer_t buffer_t;
|
||||||
HB_WASM_API_COMPOUND (buffer_contents_t, buffer_copy_contents) (HB_WASM_EXEC_ENV_COMPOUND
|
HB_WASM_API_COMPOUND (buffer_contents_t, buffer_copy_contents) (HB_WASM_EXEC_ENV_COMPOUND
|
||||||
ptr_t(buffer_t));
|
ptr_t(buffer_t));
|
||||||
|
|
||||||
|
HB_WASM_API (bool_t, buffer_set_contents) (HB_WASM_EXEC_ENV
|
||||||
|
ptr_t(buffer_t),
|
||||||
|
ptr_t(const buffer_contents_t));
|
||||||
|
|
||||||
|
|
||||||
/* face */
|
/* face */
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,15 @@ shape (font_t *font, buffer_t *buffer)
|
||||||
debugprint1 ("buffer length", contents.length);
|
debugprint1 ("buffer length", contents.length);
|
||||||
|
|
||||||
for (unsigned i = 0; i < contents.length; i++)
|
for (unsigned i = 0; i < contents.length; i++)
|
||||||
|
{
|
||||||
debugprint2 ("Codepoint", i, contents.info[i].codepoint);
|
debugprint2 ("Codepoint", i, contents.info[i].codepoint);
|
||||||
|
contents.info[i].codepoint++;
|
||||||
|
contents.pos[i].x_advance = 256 * 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool_t ret = buffer_set_contents (buffer, &contents);
|
||||||
|
|
||||||
buffer_contents_free (&contents);
|
buffer_contents_free (&contents);
|
||||||
|
|
||||||
return 1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue