diff options
Diffstat (limited to 'font/src/lib.rs')
-rw-r--r-- | font/src/lib.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/font/src/lib.rs b/font/src/lib.rs index 7ec5984c..afe2b94f 100644 --- a/font/src/lib.rs +++ b/font/src/lib.rs @@ -46,7 +46,7 @@ use std::sync::atomic::{AtomicU32, ATOMIC_U32_INIT, Ordering}; #[cfg(not(target_os = "macos"))] mod ft; #[cfg(not(target_os = "macos"))] -pub use ft::*; +pub use ft::{FreeTypeRasterizer as Rasterizer, Error}; // If target is macos, reexport everything from darwin #[cfg(target_os = "macos")] @@ -71,6 +71,12 @@ impl FontDesc { } } +impl fmt::Display for FontDesc { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "name '{}' and style '{}'", self.name, self.style) + } +} + /// Identifier for a Font for use in maps/etc #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] pub struct FontKey { @@ -156,3 +162,21 @@ pub struct Metrics { pub average_advance: f64, pub line_height: f64, } + +pub trait Rasterize { + /// Errors occurring in Rasterize methods + type Err: ::std::error::Error + Send + Sync + 'static; + + /// Create a new Rasterize + fn new(dpi_x: f32, dpi_y: f32, device_pixel_ratio: f32) -> Result<Self, Self::Err> + where Self: Sized; + + /// Get `Metrics` for the given `FontKey` and `Size` + fn metrics(&self, FontKey, Size) -> Result<Metrics, Self::Err>; + + /// Load the font described by `FontDesc` and `Size` + fn load_font(&mut self, &FontDesc, Size) -> Result<FontKey, Self::Err>; + + /// Rasterize the glyph described by `GlyphKey`. + fn get_glyph(&mut self, &GlyphKey) -> Result<RasterizedGlyph, Self::Err>; +} |