Make refactor into library
This commit is contained in:
parent
132fb02008
commit
3295b254ad
8 changed files with 449 additions and 439 deletions
33
examples/text/src/font/mod.rs
Normal file
33
examples/text/src/font/mod.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
pub use self::layout::*;
|
||||
mod layout;
|
||||
|
||||
pub use self::matches::*;
|
||||
mod matches;
|
||||
|
||||
pub use self::shape::*;
|
||||
mod shape;
|
||||
|
||||
pub use self::system::*;
|
||||
mod system;
|
||||
|
||||
pub struct Font<'a> {
|
||||
data: &'a [u8],
|
||||
pub rustybuzz: rustybuzz::Face<'a>,
|
||||
#[cfg(feature = "ab_glyph")]
|
||||
pub ab_glyph: ab_glyph::FontRef<'a>,
|
||||
#[cfg(feature = "rusttype")]
|
||||
pub rusttype: rusttype::Font<'a>,
|
||||
}
|
||||
|
||||
impl<'a> Font<'a> {
|
||||
pub fn new(data: &'a [u8], index: u32) -> Option<Self> {
|
||||
Some(Self {
|
||||
data,
|
||||
rustybuzz: rustybuzz::Face::from_slice(data, index)?,
|
||||
#[cfg(feature = "ab_glyph")]
|
||||
ab_glyph: ab_glyph::FontRef::try_from_slice_and_index(data, index).ok()?,
|
||||
#[cfg(feature = "rusttype")]
|
||||
rusttype: rusttype::Font::try_from_bytes_and_index(data, index)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue