[wasm-api] Bind shape_with

This commit is contained in:
Behdad Esfahbod 2023-02-24 11:03:13 -07:00
parent a08dbf41cd
commit 2bde2f66f1
8 changed files with 90 additions and 8 deletions

View File

@ -73,6 +73,9 @@ static NativeSymbol _hb_wasm_native_symbols[] =
NATIVE_SYMBOL ("(ii)i", font_get_glyph_h_advance),
NATIVE_SYMBOL ("(ii)i", font_get_glyph_v_advance),
/* shape */
NATIVE_SYMBOL ("(ii$)i", shape_with),
/* debug */
#ifdef HB_DEBUG_WASM
NATIVE_SYMBOL ("($)", debugprint),

50
src/hb-wasm-api-shape.hh Normal file
View File

@ -0,0 +1,50 @@
/*
* 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_SHAPE_HH
#define HB_WASM_API_SHAPE_HH
#include "hb-wasm-api.hh"
namespace hb {
namespace wasm {
bool_t
shape_with (HB_WASM_EXEC_ENV
ptr_t(font_t) fontref,
ptr_t(buffer_t) bufferref,
const char *shaper)
{
HB_REF2OBJ (font);
HB_REF2OBJ (buffer);
const char * shaper_list[] = {shaper, nullptr};
return hb_shape_full (font, buffer, nullptr, 0, shaper_list);
}
}}
#endif /* HB_WASM_API_SHAPE_HH */

View File

@ -31,6 +31,7 @@
#include "hb-wasm-api-buffer.hh"
#include "hb-wasm-api-face.hh"
#include "hb-wasm-api-font.hh"
#include "hb-wasm-api-shape.hh"
#undef module_inst

View File

@ -189,6 +189,14 @@ HB_WASM_API (hb_position_t, font_get_glyph_v_advance) (HB_WASM_EXEC_ENV
hb_codepoint_t glyph);
/* shape */
HB_WASM_INTERFACE (bool_t, shape_with) (HB_WASM_EXEC_ENV
ptr_t(font_t),
ptr_t(buffer_t),
const char *shaper);
/* shape interface */
HB_WASM_INTERFACE (bool_t, shape) (HB_WASM_EXEC_ENV

View File

@ -331,6 +331,7 @@ hb_wasm_sources = files(
'hb-wasm-api-buffer.hh',
'hb-wasm-api-face.hh',
'hb-wasm-api-font.hh',
'hb-wasm-api-shape.hh',
'hb-wasm-shape.cc',
)
hb_wasm_headers = files()

View File

@ -1,6 +1,6 @@
all: test.wasm.ttf
all: test-fallback.wasm.ttf test-ot.wasm.ttf
%.so: %.c ../hb-wasm-api.h
%.wasm: %.cc ../hb-wasm-api.h
clang \
--target=wasm32-unknown-wasi \
-Wl,--no-entry \
@ -11,10 +11,13 @@ all: test.wasm.ttf
$< \
-o $@
%.wasm.ttf: %.ttf shape.so addTable.py
python addTable.py $< $@ shape.so
test-fallback.wasm.ttf: test.ttf shape-fallback.wasm addTable.py
python addTable.py $< $@ shape-fallback.wasm
test-ot.wasm.ttf: test.ttf shape-ot.wasm addTable.py
python addTable.py $< $@ shape-ot.wasm
clean:
$(RM) test.wasm.ttf shape.so
$(RM) test-fallback.wasm.ttf test-ot.wasm.ttf shape-fallback.wasm shape-ot.wasm
.PRECIOUS: shape.so
.PRECIOUS: *.wasm

View File

@ -2,8 +2,10 @@
#include <hb-wasm-api.h>
void debugprint1 (char *s, int32_t);
void debugprint2 (char *s, int32_t, int32_t);
extern "C" {
void debugprint1 (const char *s, int32_t);
void debugprint2 (const char *s, int32_t, int32_t);
}
bool_t
shape (font_t *font, buffer_t *buffer)

View File

@ -0,0 +1,14 @@
#define HB_WASM_INTERFACE(ret_t, name) __attribute__((export_name(#name))) ret_t name
#include <hb-wasm-api.h>
extern "C" {
void debugprint1 (const char *s, int32_t);
void debugprint2 (const char *s, int32_t, int32_t);
}
bool_t
shape (font_t *font, buffer_t *buffer)
{
return shape_with (font, buffer, "ot");
}