web_sys::FontFace::load function


This example asynchronously loads a true type Code 39 barcode font using the FontFace load method. After the font is loaded, it is added to the Document to display a barcode in a div element. The load method returns a JavaScript Promise which is wrap in a Rust JsFuture. The await keyword yields control of the current thread until the font is loaded. Finally, the loaded font is added to the list of fonts available in the HTML document element.

    pub async fn web_sys_fontface_load() 
        let window = web_sys::window().expect("global window does not exists");    
        let document = window.document().expect("expecting a document on window");
        let fontface = FontFace::new_with_str("barcodefont", 
        let promise=fontface.load().unwrap();
        let _result= wasm_bindgen_futures::JsFuture::from(promise).await;

HTML div element using the "barcodefont" font-face

        <div style="font-weight: normal; font-style: normal; line-height:normal; 
        font-family: 'barcodefont', sans-serif; font-size: 32px">*12345678*</div>


	pub fn load(&self) -> Result<Promise, JsValue>


Source Code