mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Load the Noto Sans font from the nodejs printer demo
This commit is contained in:
parent
1b870959e6
commit
2fdaa44d51
3 changed files with 25 additions and 4 deletions
|
@ -233,5 +233,6 @@ module.exports = {
|
|||
ArrayModel: ArrayModel,
|
||||
Timer: {
|
||||
singleShot: native.singleshot_timer,
|
||||
}
|
||||
},
|
||||
register_font_from_path: native.register_font_from_path,
|
||||
};
|
||||
|
|
|
@ -566,10 +566,22 @@ fn singleshot_timer(mut cx: FunctionContext) -> JsResult<JsValue> {
|
|||
Ok(JsUndefined::new().upcast())
|
||||
}
|
||||
|
||||
fn register_font_from_path(mut cx: FunctionContext) -> JsResult<JsValue> {
|
||||
let path = cx.argument::<JsString>(0)?.value();
|
||||
|
||||
match sixtyfps_interpreter::register_font_from_path(&path) {
|
||||
Ok(_) => Ok(JsUndefined::new().upcast()),
|
||||
Err(load_err) => {
|
||||
return cx.throw_error(format!("error loading font {}: {}", path, load_err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
register_module!(mut m, {
|
||||
m.export_function("load", load)?;
|
||||
m.export_function("mock_elapsed_time", mock_elapsed_time)?;
|
||||
m.export_function("singleshot_timer", singleshot_timer)?;
|
||||
m.export_function("register_font_from_path", register_font_from_path)?;
|
||||
Ok(())
|
||||
});
|
||||
|
||||
|
|
|
@ -9,9 +9,17 @@
|
|||
Please contact info@sixtyfps.io for more information.
|
||||
LICENSE END */
|
||||
|
||||
// import "sixtyfps";
|
||||
require("sixtyfps");
|
||||
// import * as demo from "../ui/printerdemo.60";
|
||||
const path = require("path");
|
||||
let sixtyfps = require("sixtyfps");
|
||||
|
||||
try {
|
||||
for (font_file of ["NotoSans-Regular.ttf", "NotoSans-Bold.ttf"]) {
|
||||
sixtyfps.register_font_from_path(path.resolve(__dirname, "../ui/fonts", font_file));
|
||||
}
|
||||
} catch (load_exception) {
|
||||
console.error(load_exception);
|
||||
}
|
||||
|
||||
let demo = require("../ui/printerdemo.60");
|
||||
let window = new demo.MainWindow();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue