[wasm-api] Reuse allocation in font_copy_glyph_outline

This commit is contained in:
Behdad Esfahbod 2023-02-25 10:25:19 -07:00
parent 41362cc339
commit 7fff4a19ad
3 changed files with 21 additions and 1 deletions

View File

@ -136,6 +136,25 @@ HB_WASM_API (bool_t, font_copy_glyph_outline) (HB_WASM_EXEC_ENV
return false; return false;
} }
// TODO Check two buffers separately
if (hb_outline.points.length <= outline->n_points &&
hb_outline.contours.length <= outline->n_contours)
{
glyph_outline_point_t *points = (glyph_outline_point_t *) (validate_app_addr (outline->points, hb_outline.points.get_size ()) ? addr_app_to_native (outline->points) : nullptr);
uint32_t *contours = (uint32_t *) (validate_app_addr (outline->contours, hb_outline.contours.get_size ()) ? addr_app_to_native (outline->contours) : nullptr);
if (unlikely (!points || !contours))
{
outline->n_points = outline->n_contours = 0;
return false;
}
memcpy (points, hb_outline.points.arrayZ, hb_outline.points.get_size ());
memcpy (contours, hb_outline.contours.arrayZ, hb_outline.contours.get_size ());
return true;
}
outline->n_points = hb_outline.points.length; outline->n_points = hb_outline.points.length;
outline->points = wasm_runtime_module_dup_data (module_inst, outline->points = wasm_runtime_module_dup_data (module_inst,
(const char *) hb_outline.points.arrayZ, (const char *) hb_outline.points.arrayZ,

View File

@ -252,6 +252,7 @@ typedef struct
uint32_t n_contours; uint32_t n_contours;
ptr_t(uint32_t) contours; ptr_t(uint32_t) contours;
} glyph_outline_t; } glyph_outline_t;
#define GLYPH_OUTLINE_INIT {0, 0, 0, 0}
HB_WASM_API (bool_t, font_copy_glyph_outline) (HB_WASM_EXEC_ENV HB_WASM_API (bool_t, font_copy_glyph_outline) (HB_WASM_EXEC_ENV
ptr_d(font_t, font), ptr_d(font_t, font),

View File

@ -41,7 +41,7 @@ shape (void *shape_plan,
contents.info[i].codepoint = font_get_glyph (font, contents.info[i].codepoint, 0); 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); contents.pos[i].x_advance = font_get_glyph_h_advance (font, contents.info[i].codepoint);
glyph_outline_t outline; glyph_outline_t outline = GLYPH_OUTLINE_INIT;
font_copy_glyph_outline (font, contents.info[i].codepoint, &outline); font_copy_glyph_outline (font, contents.info[i].codepoint, &outline);
debugprint1 ("num outline contours", outline.n_contours); debugprint1 ("num outline contours", outline.n_contours);
} }