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_id(id: usize) -> Self {
12        Self {
13            id: FontId(id),
14            data: [].into()
15        }
16    }
17    
18    pub fn from_font_id(font_id: FontId) -> Self {
19        Self {
20            id: font_id,
21            data: [].into()
22        }
23    }
24    
25    pub fn from_bytes_vec(id: usize, bytes: Vec<u8>) -> Self {
26        Self {
27            id: FontId(id),
28            data: bytes.into(),
29        }
30    }
31
32    pub fn from_bytes(id: usize, bytes: &[u8]) -> Self {
33        Self {
34            id: FontId(id),
35            data: bytes.into(),
36        }
37    }
38
39    pub fn from_path(id: usize, path: &str) -> Self {
40        Self::from_bytes_vec(id, std::fs::read(path).expect("Could not read/find font file"))
41    }
42}