remove draw / gfx, baseline

This commit is contained in:
Krzosa Karol
2025-01-22 14:46:07 +01:00
parent 223038c9cd
commit b20a507834
8 changed files with 24 additions and 168 deletions

View File

@@ -150,20 +150,21 @@ const ctx2d = canvas.getContext('2d');
wasm_draw_text: (str, len, x, y, font_str, font_len, font_size, r, g, b, a) => {
ctx2d.font = `${font_size}px ${mem.read_cstr(font_str, font_len)}`;
ctx2d.fillStyle = `rgba(${r}, ${g}, ${b}, ${a})`;
ctx2d.textBaseline = "hanging";
ctx2d.textBaseline = "top";
ctx2d.fillText(mem.read_cstr(str, len), x, y);
},
wasm_measure_text: (str, len, font_str, font_len, font_size) => {
ctx2d.font = `${font_size}px ${mem.read_cstr(font_str, font_len)}`;
ctx2d.textBaseline = "hanging";
ctx2d.textBaseline = "top";
const metrics = ctx2d.measureText(mem.read_cstr(str, len));
return metrics.width;
},
wasm_get_font_height: (font_str, font_len, font_size) => {
ctx2d.font = `${font_size}px ${mem.read_cstr(font_str, font_len)}`;
ctx2d.textBaseline = "hanging";
return ctx2d.measureText('NothinBelowTheBaseline').actualBoundingBoxDescent;
},
// wasm_get_font_height: (font_str, font_len, font_size) => {
// ctx2d.font = `${font_size}px ${mem.read_cstr(font_str, font_len)}`;
// ctx2d.textBaseline = "top";
// const v = ctx2d.measureText('NothinBelowTheBaseline');
// return v.fontBoundingBoxDescent;
// },
wasm_draw_rect: (x, y, w, h, r, g, b, a) => {
ctx2d.beginPath();
ctx2d.rect(x, y, w, h);