Load the Noto Sans font from the nodejs printer demo

This commit is contained in:
Simon Hausmann 2021-02-18 15:40:16 +01:00 committed by Olivier Goffart
parent 1b870959e6
commit 2fdaa44d51
3 changed files with 25 additions and 4 deletions

View file

@ -233,5 +233,6 @@ module.exports = {
ArrayModel: ArrayModel,
Timer: {
singleShot: native.singleshot_timer,
}
},
register_font_from_path: native.register_font_from_path,
};

View file

@ -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(())
});