diff --git a/src/hb-wasm-api-font.hh b/src/hb-wasm-api-font.hh index 4c641e971..10f1a30c2 100644 --- a/src/hb-wasm-api-font.hh +++ b/src/hb-wasm-api-font.hh @@ -174,6 +174,22 @@ HB_WASM_API (bool_t, font_copy_glyph_outline) (HB_WASM_EXEC_ENV return true; } +HB_WASM_API (void, glyph_outline_free) (HB_WASM_EXEC_ENV + ptr_d(glyph_outline_t, outline)) +{ + HB_PTR_PARAM (glyph_outline_t, outline); + if (unlikely (!outline)) + return; + + module_free (outline->points); + module_free (outline->contours); + + outline->n_points = 0; + outline->points = nullref; + outline->n_contours = 0; + outline->contours = nullref; +} + }} diff --git a/src/hb-wasm-api-list.hh b/src/hb-wasm-api-list.hh index 4e5172450..2f0ede178 100644 --- a/src/hb-wasm-api-list.hh +++ b/src/hb-wasm-api-list.hh @@ -80,6 +80,9 @@ static NativeSymbol _hb_wasm_native_symbols[] = NATIVE_SYMBOL ("(ii$*)", font_glyph_to_string), NATIVE_SYMBOL ("(iii)i", font_copy_glyph_outline), + /* outline */ + NATIVE_SYMBOL ("(i)", glyph_outline_free), + /* shape */ NATIVE_SYMBOL ("(iiii$)i", shape_with), diff --git a/src/hb-wasm-api.h b/src/hb-wasm-api.h index 9d8e9168f..94cf58fd4 100644 --- a/src/hb-wasm-api.h +++ b/src/hb-wasm-api.h @@ -254,11 +254,15 @@ typedef struct } glyph_outline_t; #define GLYPH_OUTLINE_INIT {0, 0, 0, 0} +HB_WASM_API (void, glyph_outline_free) (HB_WASM_EXEC_ENV + ptr_d(glyph_outline_t, outline)); + HB_WASM_API (bool_t, font_copy_glyph_outline) (HB_WASM_EXEC_ENV ptr_d(font_t, font), codepoint_t glyph, ptr_d(glyph_outline_t, outline)); + /* shape */ typedef struct diff --git a/src/wasm/sample/c/shape-fallback.cc b/src/wasm/sample/c/shape-fallback.cc index 9bb3a688f..7787bbae7 100644 --- a/src/wasm/sample/c/shape-fallback.cc +++ b/src/wasm/sample/c/shape-fallback.cc @@ -30,10 +30,14 @@ shape (void *shape_plan, debugprint1 ("buffer length", contents.length); + glyph_outline_t outline = GLYPH_OUTLINE_INIT; + for (unsigned i = 0; i < contents.length; i++) { char name[64]; + debugprint1 ("glyph at", i); + font_glyph_to_string (font, contents.info[i].codepoint, name, sizeof (name)); debugprint (name); @@ -41,11 +45,13 @@ shape (void *shape_plan, contents.info[i].codepoint = font_get_glyph (font, contents.info[i].codepoint, 0); contents.pos[i].x_advance = font_get_glyph_h_advance (font, contents.info[i].codepoint); - glyph_outline_t outline = GLYPH_OUTLINE_INIT; font_copy_glyph_outline (font, contents.info[i].codepoint, &outline); + debugprint1 ("num outline points", outline.n_points); debugprint1 ("num outline contours", outline.n_contours); } + glyph_outline_free (&outline); + bool_t ret = buffer_set_contents (buffer, &contents); buffer_contents_free (&contents);