plotters/style/font/
mod.rs

1/// The implementation of an actual font implementation
2///
3/// This exists since for the image rendering task, we want to use
4/// the system font. But in wasm application, we want the browser
5/// to handle all the font issue.
6///
7/// Thus we need different mechanism for the font implementation
8
9#[cfg(all(not(target_arch = "wasm32"), feature = "ttf"))]
10mod ttf;
11#[cfg(all(not(target_arch = "wasm32"), feature = "ttf"))]
12use ttf::FontDataInternal;
13
14#[cfg(all(not(target_arch = "wasm32"), not(feature = "ttf")))]
15mod naive;
16#[cfg(all(not(target_arch = "wasm32"), not(feature = "ttf")))]
17use naive::FontDataInternal;
18
19#[cfg(target_arch = "wasm32")]
20mod web;
21#[cfg(target_arch = "wasm32")]
22use web::FontDataInternal;
23
24mod font_desc;
25pub use font_desc::*;
26
27pub type LayoutBox = ((i32, i32), (i32, i32));
28
29pub trait FontData: Clone {
30    type ErrorType: Sized + std::error::Error + Clone;
31    fn new(family: FontFamily, style: FontStyle) -> Result<Self, Self::ErrorType>;
32    fn estimate_layout(&self, size: f64, text: &str) -> Result<LayoutBox, Self::ErrorType>;
33    fn draw<E, DrawFunc: FnMut(i32, i32, f32) -> Result<(), E>>(
34        &self,
35        _pos: (i32, i32),
36        _size: f64,
37        _text: &str,
38        _draw: DrawFunc,
39    ) -> Result<Result<(), E>, Self::ErrorType> {
40        panic!("The font implementation is unable to draw text");
41    }
42}