Skip to main content

flake/misc/
font.rs

1use std::sync::Arc;
2use wgpu_text::glyph_brush::FontId;
3
4#[derive(Clone, PartialEq)]
5pub struct Font {
6    pub id: FontId,
7    pub data: Arc<[u8]>,
8}
9
10impl Font {
11    pub fn from_bytes_vec(id: usize, bytes: Vec<u8>) -> Self {
12        Self {
13            id: FontId(id),
14            data: bytes.into(),
15        }
16    }
17
18    pub fn from_bytes(id: usize, bytes: &[u8]) -> Self {
19        Self {
20            id: FontId(id),
21            data: bytes.into(),
22        }
23    }
24
25    pub fn from_path(id: usize, path: &str) -> Self {
26        Self::from_bytes_vec(id, std::fs::read(path).expect("Could not read/find font file"))
27    }
28}