[wasm-api] Add glyph_outline_free

This commit is contained in:
Behdad Esfahbod 2023-02-25 10:29:03 -07:00
parent 7fff4a19ad
commit 918df8ccaf
4 changed files with 30 additions and 1 deletions

View File

@ -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;
}
}}

View File

@ -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),

View File

@ -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

View File

@ -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);