wasm, ui, dpi and text baseline

This commit is contained in:
Krzosa Karol
2025-01-22 13:11:04 +01:00
parent e54265fcac
commit 223038c9cd
7 changed files with 46 additions and 38 deletions

View File

@@ -13,8 +13,8 @@
</body>
<style>
@font-face {
font-family: open_sans_regular;
src: url(OpenSans-Regular.ttf);
font-family: main_font;
src: url(FiraCode-Regular.ttf);
}
* {
margin: 0;
@@ -150,18 +150,18 @@ 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 = "top"
ctx2d.fillText(mem.read_cstr(str, len), x, y)
ctx2d.textBaseline = "hanging";
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 = "top";
ctx2d.textBaseline = "hanging";
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 = "top";
ctx2d.textBaseline = "hanging";
return ctx2d.measureText('NothinBelowTheBaseline').actualBoundingBoxDescent;
},
wasm_draw_rect: (x, y, w, h, r, g, b, a) => {