diff --git a/src/hb-wasm-api-font.hh b/src/hb-wasm-api-font.hh index d1401c7e0..4c641e971 100644 --- a/src/hb-wasm-api-font.hh +++ b/src/hb-wasm-api-font.hh @@ -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, diff --git a/src/hb-wasm-api.h b/src/hb-wasm-api.h index 0b09f4de9..9d8e9168f 100644 --- a/src/hb-wasm-api.h +++ b/src/hb-wasm-api.h @@ -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), diff --git a/src/wasm/sample/c/shape-fallback.cc b/src/wasm/sample/c/shape-fallback.cc index 0a2ab9e09..9bb3a688f 100644 --- a/src/wasm/sample/c/shape-fallback.cc +++ b/src/wasm/sample/c/shape-fallback.cc @@ -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); }