Store font as peniko::Font behind feature flag (#375)
* Allow exposing Peniko font from cosmic text * . * . * . * .
This commit is contained in:
parent
6598c7cae8
commit
695745ac4f
2 changed files with 27 additions and 1 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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<dyn AsRef<[u8]> + Send + Sync>,
|
||||
#[cfg(feature = "peniko")]
|
||||
data: peniko::Font,
|
||||
id: fontdb::ID,
|
||||
monospace_fallback: Option<FontMonospaceFallback>,
|
||||
}
|
||||
|
|
@ -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),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue