diff --git a/Cargo.toml b/Cargo.toml index 5ec1fa1..e0f05e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,11 +40,16 @@ version = "0.3.13" default-features = false features = ["hardcoded-data"] +[dependencies.peniko] +version = "0.3.1" +optional = true + [features] default = ["std", "swash", "fontconfig"] fontconfig = ["fontdb/fontconfig", "std"] monospace_fallback = [] no_std = ["rustybuzz/libm", "hashbrown", "dep:libm"] +peniko = ["dep:peniko"] shape-run-cache = [] std = [ "fontdb/memmap", diff --git a/src/font/mod.rs b/src/font/mod.rs index d5e7c07..cb9182a 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -2,6 +2,9 @@ // re-export ttf_parser pub use ttf_parser; +// re-export peniko::Font; +#[cfg(feature = "peniko")] +pub use peniko::Font as PenikoFont; use core::fmt; @@ -38,7 +41,10 @@ pub struct Font { #[cfg(feature = "swash")] swash: (u32, swash::CacheKey), rustybuzz: OwnedFace, + #[cfg(not(feature = "peniko"))] data: Arc + Send + Sync>, + #[cfg(feature = "peniko")] + data: peniko::Font, id: fontdb::ID, monospace_fallback: Option, } @@ -73,13 +79,25 @@ impl Font { } pub fn data(&self) -> &[u8] { - (*self.data).as_ref() + #[cfg(not(feature = "peniko"))] + { + (*self.data).as_ref() + } + #[cfg(feature = "peniko")] + { + self.data.data.data() + } } pub fn rustybuzz(&self) -> &RustybuzzFace<'_> { self.rustybuzz.borrow_dependent() } + #[cfg(feature = "peniko")] + pub fn as_peniko(&self) -> PenikoFont { + self.data.clone() + } + #[cfg(feature = "swash")] pub fn as_swash(&self) -> swash::FontRef<'_> { let swash = &self.swash; @@ -171,7 +189,10 @@ impl Font { RustybuzzFace::from_slice((**data).as_ref(), info.index).ok_or(()) }) .ok()?, + #[cfg(not(feature = "peniko"))] data, + #[cfg(feature = "peniko")] + data: peniko::Font::new(peniko::Blob::new(data), info.index), }) } }