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(
10 not(all(target_arch = "wasm32", not(target_os = "wasi"))),
11 feature = "ttf"
12))]
13mod ttf;
14#[cfg(all(
15 not(all(target_arch = "wasm32", not(target_os = "wasi"))),
16 feature = "ttf"
17))]
18use ttf::FontDataInternal;
19
20#[cfg(all(
21 not(target_arch = "wasm32"),
22 not(target_os = "wasi"),
23 feature = "ab_glyph"
24))]
25mod ab_glyph;
26#[cfg(all(
27 not(target_arch = "wasm32"),
28 not(target_os = "wasi"),
29 feature = "ab_glyph"
30))]
31pub use self::ab_glyph::register_font;
32#[cfg(all(
33 not(target_arch = "wasm32"),
34 not(target_os = "wasi"),
35 feature = "ab_glyph",
36 not(feature = "ttf")
37))]
38use self::ab_glyph::FontDataInternal;
39
40#[cfg(all(
41 not(all(target_arch = "wasm32", not(target_os = "wasi"))),
42 not(feature = "ttf"),
43 not(feature = "ab_glyph")
44))]
45mod naive;
46#[cfg(all(
47 not(all(target_arch = "wasm32", not(target_os = "wasi"))),
48 not(feature = "ttf"),
49 not(feature = "ab_glyph")
50))]
51use naive::FontDataInternal;
52
53#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
54mod web;
55#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
56use web::FontDataInternal;
57
58mod font_desc;
59pub use font_desc::*;
60
61/// Represents a box where a text label can be fit
62pub type LayoutBox = ((i32, i32), (i32, i32));
63
64pub trait FontData: Clone {
65 type ErrorType: Sized + std::error::Error + Clone;
66 fn new(family: FontFamily, style: FontStyle) -> Result<Self, Self::ErrorType>;
67 fn estimate_layout(&self, size: f64, text: &str) -> Result<LayoutBox, Self::ErrorType>;
68 fn draw<E, DrawFunc: FnMut(i32, i32, f32) -> Result<(), E>>(
69 &self,
70 _pos: (i32, i32),
71 _size: f64,
72 _text: &str,
73 _draw: DrawFunc,
74 ) -> Result<Result<(), E>, Self::ErrorType> {
75 panic!("The font implementation is unable to draw text");
76 }
77}
78