[wasm-api] Reuse allocation in font_copy_glyph_outline
This commit is contained in:
parent
41362cc339
commit
7fff4a19ad
|
@ -136,6 +136,25 @@ HB_WASM_API (bool_t, font_copy_glyph_outline) (HB_WASM_EXEC_ENV
|
|||
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->points = wasm_runtime_module_dup_data (module_inst,
|
||||
(const char *) hb_outline.points.arrayZ,
|
||||
|
|
|
@ -252,6 +252,7 @@ typedef struct
|
|||
uint32_t n_contours;
|
||||
ptr_t(uint32_t) contours;
|
||||
} glyph_outline_t;
|
||||
#define GLYPH_OUTLINE_INIT {0, 0, 0, 0}
|
||||
|
||||
HB_WASM_API (bool_t, font_copy_glyph_outline) (HB_WASM_EXEC_ENV
|
||||
ptr_d(font_t, font),
|
||||
|
|
|
@ -41,7 +41,7 @@ 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_t outline = GLYPH_OUTLINE_INIT;
|
||||
font_copy_glyph_outline (font, contents.info[i].codepoint, &outline);
|
||||
debugprint1 ("num outline contours", outline.n_contours);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue