index/utils/
font_face.rs

1use std::rc::Rc;
2
3use wasm_bindgen::prelude::*;
4
5/// A FontFace represents a font that can be used for rendering text.
6#[wasm_bindgen]
7#[derive(Clone, Debug, PartialEq)]
8pub struct FontFace {
9    /// The data of the font face.
10    data: Rc<Vec<u8>>,
11}
12
13#[wasm_bindgen]
14impl FontFace {
15    /// Creates a new FontFace from font data.
16    #[wasm_bindgen(constructor, return_description = "A new font face.")]
17    pub fn new(
18        #[wasm_bindgen(param_description = "The data of the font face.")]
19        data: Vec<u8>,
20    ) -> FontFace {
21        FontFace { data: Rc::new(data) }
22    }
23
24    /// Returns the data of the font face.
25    #[wasm_bindgen(getter, return_description = "The data of the font face.")]
26    pub fn data(&self) -> Vec<u8> {
27        self.data.to_vec()
28    }
29
30    /// Clones the font face.
31    #[wasm_bindgen(js_name = clone)]
32    pub fn copy(&self) -> FontFace {
33        self.clone()
34    }
35}