web_sys::FontFace::new_with_str function

Example

This example uses the new_with_str method to create a new instance of FontFace. The method takes in two parameters, a name that will be used as the font face value for font-family properties, and a second parameter, the font source, which can be a URL or binary font data. In our scenario below, both a URL to a True Type font and an Open Type font are demonstrated.

Free Fonts, courtesy of BarcodeResource

https://barcoderesource.com/freebarcodefont.shtml


    pub fn web_sys_fontface_new_with_str() 
    {
        let window = web_sys::window().expect("global window does not exists");    
        let _document = window.document().expect("expecting a document on window");
        let _fontface_ttf = FontFace::new_with_str("barcodefont", 
                            "url(ConnectCode39.ttf)").unwrap();
        let _fontface_otf = FontFace::new_with_str("barcodefont", 
                            "url(ConnectCode39.otf)").unwrap();
        
        /*
        let promise_ttf=fontface_ttf.load().unwrap();
        let promise_otf=fontface_otf.load().unwrap();
    
        let result= wasm_bindgen_futures::JsFuture::from(promise_ttf).await;
        let result= wasm_bindgen_futures::JsFuture::from(promise_otf).await;
    
        document.fonts().add(&fontface_ttf);    
        document.fonts().add(&fontface_otf);    
        */
    
    }    

Function


	pub fn new_with_str(family: &str, source: &str) -> Result<FontFace, JsValue>

features/dependencies

Source Code