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"))] 10 mod ttf; 11 #[cfg(all(not(target_arch = "wasm32"), feature = "ttf"))] 12 use ttf::FontDataInternal; 13 14 #[cfg(all(not(target_arch = "wasm32"), not(feature = "ttf")))] 15 mod naive; 16 #[cfg(all(not(target_arch = "wasm32"), not(feature = "ttf")))] 17 use naive::FontDataInternal; 18 19 #[cfg(target_arch = "wasm32")] 20 mod web; 21 #[cfg(target_arch = "wasm32")] 22 use web::FontDataInternal; 23 24 mod font_desc; 25 pub use font_desc::*; 26 27 pub type LayoutBox = ((i32, i32), (i32, i32)); 28 29 pub trait FontData: Clone { 30 type ErrorType: Sized + std::error::Error + Clone; new(family: FontFamily, style: FontStyle) -> Result<Self, Self::ErrorType>31 fn new(family: FontFamily, style: FontStyle) -> Result<Self, Self::ErrorType>; estimate_layout(&self, size: f64, text: &str) -> Result<LayoutBox, Self::ErrorType>32 fn estimate_layout(&self, size: f64, text: &str) -> Result<LayoutBox, Self::ErrorType>; draw<E, DrawFunc: FnMut(i32, i32, f32) -> Result<(), E>>( &self, _pos: (i32, i32), _size: f64, _text: &str, _draw: DrawFunc, ) -> Result<Result<(), E>, 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 } 43