plotters/style/font/
naive.rs1use super::{FontData, FontFamily, FontStyle, LayoutBox};
2
3#[derive(Debug, Clone)]
4pub struct FontError;
5
6impl std::fmt::Display for FontError {
7 fn fmt(&self, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
8 write!(fmt, "General Error")?;
9 Ok(())
10 }
11}
12
13impl std::error::Error for FontError {}
14
15#[derive(Clone)]
16pub struct FontDataInternal(String, String);
17
18impl FontData for FontDataInternal {
19 type ErrorType = FontError;
20 fn new(family: FontFamily, style: FontStyle) -> Result<Self, FontError> {
21 Ok(FontDataInternal(
22 family.as_str().into(),
23 style.as_str().into(),
24 ))
25 }
26
27 fn estimate_layout(&self, size: f64, text: &str) -> Result<LayoutBox, Self::ErrorType> {
31 let em = size / 1.24 / 1.24;
32 Ok((
33 (0, -em.round() as i32),
34 (
35 (em * 0.7 * text.len() as f64).round() as i32,
36 (em * 0.24).round() as i32,
37 ),
38 ))
39 }
40}