[wasm-api] Bind buffer_copy_contents

This commit is contained in:
Behdad Esfahbod 2023-02-23 13:58:40 -07:00
parent 50b22368d0
commit 5cecfe8659
7 changed files with 120 additions and 10 deletions

58
src/hb-wasm-api-buffer.hh Normal file
View File

@ -0,0 +1,58 @@
/*
* Copyright © 2023 Behdad Esfahbod
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
#ifndef HB_WASM_API_BUFFER_HH
#define HB_WASM_API_BUFFER_HH
#include "hb-wasm-api.hh"
#include "hb-buffer.hh"
namespace hb {
namespace wasm {
void
buffer_copy_contents (HB_WASM_EXEC_ENV_COMPOUND
buffer_t bufferref)
{
HB_RETURN_TYPE (buffer_contents_t, ret);
HB_REF2OBJ (buffer);
if (buffer->have_output)
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;
ret.length = length;
ret.info = wasm_runtime_module_dup_data (module_inst, (const char *) buffer->info, length * sizeof (buffer->info[0]));
ret.pos = wasm_runtime_module_dup_data (module_inst, (const char *) buffer->pos, length * sizeof (buffer->pos[0]));
}
}}
#endif /* HB_WASM_API_BUFFER_HH */

View File

@ -22,10 +22,10 @@
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
#ifndef HB_WASM_FACE_HH
#define HB_WASM_FACE_HH
#ifndef HB_WASM_API_FACE_HH
#define HB_WASM_API_FACE_HH
#include <hb-wasm-api.hh>
#include "hb-wasm-api.hh"
namespace hb {
namespace wasm {
@ -53,4 +53,4 @@ face_reference_table (HB_WASM_EXEC_ENV_COMPOUND
}}
#endif /* HB_WASM_FACE_HH */
#endif /* HB_WASM_API_FACE_HH */

View File

@ -22,10 +22,10 @@
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
#ifndef HB_WASM_FONT_HH
#define HB_WASM_FONT_HH
#ifndef HB_WASM_API_FONT_HH
#define HB_WASM_API_FONT_HH
#include <hb-wasm-api.hh>
#include "hb-wasm-api.hh"
namespace hb {
namespace wasm {
@ -46,4 +46,4 @@ font_get_face (HB_WASM_EXEC_ENV
}}
#endif /* HB_WASM_FONT_HH */
#endif /* HB_WASM_API_FONT_HH */

View File

@ -51,6 +51,9 @@ static void debugprint4 (HB_WASM_EXEC_ENV char *str, int32_t i1, int32_t i2, int
static NativeSymbol _hb_wasm_native_symbols[] =
{
/* buffer */
NATIVE_SYMBOL ("(ii)", buffer_copy_contents),
/* face */
NATIVE_SYMBOL ("(iii)", face_reference_table),

View File

@ -27,6 +27,7 @@
#define module_inst wasm_runtime_get_module_inst (exec_env)
#include "hb-wasm-api-buffer.hh"
#include "hb-wasm-api-face.hh"
#include "hb-wasm-api-font.hh"

View File

@ -72,6 +72,9 @@ HB_WASM_BEGIN_DECLS
#define ptr_t(type_t) type_t *
#endif
typedef uint32_t hb_codepoint_t;
typedef int32_t hb_position_t;
typedef uint32_t hb_mask_t;
typedef uint32_t tag_t;
#define TAG(c1,c2,c3,c4) ((tag_t)((((uint32_t)(c1)&0xFF)<<24)|(((uint32_t)(c2)&0xFF)<<16)|(((uint32_t)(c3)&0xFF)<<8)|((uint32_t)(c4)&0xFF)))
@ -79,12 +82,50 @@ typedef ref_t face_t;
typedef ref_t font_t;
typedef ref_t buffer_t;
/* blob */
typedef struct
{
ptr_t(char) data;
uint32_t length;
ptr_t(char) data;
} blob_t;
/* TODO blob_free */
/* buffer */
typedef struct
{
uint32_t codepoint;
uint32_t mask;
uint32_t cluster;
uint32_t var1;
uint32_t var2;
} glyph_info_t;
typedef struct
{
hb_position_t x_advance;
hb_position_t y_advance;
hb_position_t x_offset;
hb_position_t y_offset;
uint32_t var;
} glyph_position_t;
typedef struct
{
uint32_t length;
ptr_t(glyph_info_t) info;
ptr_t(glyph_position_t) pos;
} buffer_contents_t;
/* TODO buffer_contents_free */
HB_WASM_API_COMPOUND (buffer_contents_t, buffer_copy_contents) (HB_WASM_EXEC_ENV_COMPOUND
buffer_t bufferref);
/* face */

View File

@ -324,7 +324,14 @@ hb_glib_headers = files('hb-glib.h')
hb_graphite2_sources = files('hb-graphite2.cc')
hb_graphite2_headers = files('hb-graphite2.h')
hb_wasm_sources = files('hb-wasm-shape.cc', 'hb-wasm-api.cc')
hb_wasm_sources = files(
'hb-wasm-api.cc',
'hb-wasm-api.hh',
'hb-wasm-api-buffer.hh',
'hb-wasm-api-face.hh',
'hb-wasm-api-font.hh',
'hb-wasm-shape.cc',
)
hb_wasm_headers = files()
# System-dependent sources and headers