| 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 | ))] |
| 13 | mod ttf; |
| 14 | #[cfg (all( |
| 15 | not(all(target_arch = "wasm32" , not(target_os = "wasi" ))), |
| 16 | feature = "ttf" |
| 17 | ))] |
| 18 | use ttf::FontDataInternal; |
| 19 | |
| 20 | #[cfg (all( |
| 21 | not(target_arch = "wasm32" ), |
| 22 | not(target_os = "wasi" ), |
| 23 | feature = "ab_glyph" |
| 24 | ))] |
| 25 | mod ab_glyph; |
| 26 | #[cfg (all( |
| 27 | not(target_arch = "wasm32" ), |
| 28 | not(target_os = "wasi" ), |
| 29 | feature = "ab_glyph" |
| 30 | ))] |
| 31 | pub 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 | ))] |
| 38 | use 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 | ))] |
| 45 | mod naive; |
| 46 | #[cfg (all( |
| 47 | not(all(target_arch = "wasm32" , not(target_os = "wasi" ))), |
| 48 | not(feature = "ttf" ), |
| 49 | not(feature = "ab_glyph" ) |
| 50 | ))] |
| 51 | use naive::FontDataInternal; |
| 52 | |
| 53 | #[cfg (all(target_arch = "wasm32" , not(target_os = "wasi" )))] |
| 54 | mod web; |
| 55 | #[cfg (all(target_arch = "wasm32" , not(target_os = "wasi" )))] |
| 56 | use web::FontDataInternal; |
| 57 | |
| 58 | mod font_desc; |
| 59 | pub use font_desc::*; |
| 60 | |
| 61 | /// Represents a box where a text label can be fit |
| 62 | pub type LayoutBox = ((i32, i32), (i32, i32)); |
| 63 | |
| 64 | pub 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 | |