feat: start fonts ingesting
This commit is contained in:
31
dot-matrix/src/font/font.rs
Normal file
31
dot-matrix/src/font/font.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
const FONT_5x7_JSON: &str = include_str!("../../assets/fonts/5x7.json");
|
||||
|
||||
pub struct Font {
|
||||
pub name: String,
|
||||
pub size: f64,
|
||||
pub font_json: String,
|
||||
}
|
||||
|
||||
/// Return the embedded font JSON by string key
|
||||
pub fn get_font_json(name: &str) -> Option<&'static str> {
|
||||
match name {
|
||||
"5x7" => Some(FONT_5x7_JSON),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
impl Font {
|
||||
pub fn new(name: &str, size: f64) -> Self {
|
||||
Self {
|
||||
font_json: get_font_json(name)
|
||||
.unwrap_or_else(|| panic!("Unknown font: {}", name))
|
||||
.to_string(),
|
||||
name: name.to_string(),
|
||||
size,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn description(&self) -> String {
|
||||
format!("{} {}", self.name, self.size)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user