plotters_unsable/style/font/
mod.rs

1/// The implementation of an actual font implmentation
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(not(target_arch = "wasm32"))]
10mod ttf;
11
12#[cfg(not(target_arch = "wasm32"))]
13#[allow(unused_imports, dead_code)]
14use ttf::FontDataInternal;
15
16#[cfg(target_arch = "wasm32")]
17mod web;
18#[cfg(target_arch = "wasm32")]
19use web::FontDataInternal;
20
21mod font_desc;
22pub use font_desc::*;
23
24pub type LayoutBox = ((i32, i32), (i32, i32));
25
26pub trait FontData: Clone {
27    type ErrorType: Sized + std::error::Error + Clone;
28    fn new(face: &str) -> Result<Self, Self::ErrorType>;
29    fn estimate_layout(&self, size: f64, text: &str) -> Result<LayoutBox, Self::ErrorType>;
30    fn draw<E, DrawFunc: FnMut(i32, i32, f32) -> Result<(), E>>(
31        &self,
32        _pos: (i32, i32),
33        _size: f64,
34        _text: &str,
35        _trans: FontTransform,
36        _draw: DrawFunc,
37    ) -> Result<Result<(), E>, Self::ErrorType> {
38        panic!("The font implementation is unable to rasterize font");
39    }
40}