wasm, ui, dpi and text baseline
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user