1use std::sync::Arc;
2
3#[derive(Clone)]
4pub struct Font {
5 pub font: Arc<fontdue::Font>,
6}
7
8impl Font {
9 pub fn new(path: &str) -> Result<Self, String> {
10 let bytes = std::fs::read(path)
11 .map_err(|_| format!("Could not find font file: {}", path))?;
12 let font = fontdue::Font::from_bytes(
13 bytes,
14 fontdue::FontSettings {
15 scale: 16.0,
16 load_substitutions: true,
17 ..Default::default()
18 },
19 )
20 .map_err(|e| format!("Could not create font: {}", e))?;
21 Ok(Self { font: Arc::new(font) })
22 }
23 pub fn as_slice(&self) -> [&fontdue::Font; 1] {
24 [&self.font]
25 }
26}