diff --git a/src/hb-wasm-api-list.hh b/src/hb-wasm-api-list.hh index e857e4d9e..5cd0ea6ea 100644 --- a/src/hb-wasm-api-list.hh +++ b/src/hb-wasm-api-list.hh @@ -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), diff --git a/src/hb-wasm-api-shape.hh b/src/hb-wasm-api-shape.hh new file mode 100644 index 000000000..625ff9fca --- /dev/null +++ b/src/hb-wasm-api-shape.hh @@ -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 */ diff --git a/src/hb-wasm-api.cc b/src/hb-wasm-api.cc index f09b3831d..bc3babd56 100644 --- a/src/hb-wasm-api.cc +++ b/src/hb-wasm-api.cc @@ -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 diff --git a/src/hb-wasm-api.h b/src/hb-wasm-api.h index 3f3b035d3..946e1aa92 100644 --- a/src/hb-wasm-api.h +++ b/src/hb-wasm-api.h @@ -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 diff --git a/src/meson.build b/src/meson.build index 32076c278..74998ce42 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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() diff --git a/src/wasm-sample/Makefile b/src/wasm-sample/Makefile index d072e1e50..60606e359 100644 --- a/src/wasm-sample/Makefile +++ b/src/wasm-sample/Makefile @@ -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 diff --git a/src/wasm-sample/shape.c b/src/wasm-sample/shape-fallback.cc similarity index 88% rename from src/wasm-sample/shape.c rename to src/wasm-sample/shape-fallback.cc index 1b2f4f44f..344ab0e8d 100644 --- a/src/wasm-sample/shape.c +++ b/src/wasm-sample/shape-fallback.cc @@ -2,8 +2,10 @@ #include -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) diff --git a/src/wasm-sample/shape-ot.cc b/src/wasm-sample/shape-ot.cc new file mode 100644 index 000000000..10e1e723d --- /dev/null +++ b/src/wasm-sample/shape-ot.cc @@ -0,0 +1,14 @@ +#define HB_WASM_INTERFACE(ret_t, name) __attribute__((export_name(#name))) ret_t name + +#include + +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"); +}