2022-10-24 08:56:48 -06:00
|
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
|
|
2022-11-15 12:26:59 -07:00
|
|
|
use core::ops::Deref;
|
2022-10-18 12:07:22 -06:00
|
|
|
|
2022-11-15 12:26:59 -07:00
|
|
|
pub(crate) mod fallback;
|
2022-10-18 17:13:48 -06:00
|
|
|
|
2022-10-18 12:07:22 -06:00
|
|
|
pub use self::matches::*;
|
|
|
|
|
mod matches;
|
|
|
|
|
|
|
|
|
|
pub use self::system::*;
|
|
|
|
|
mod system;
|
2022-11-15 12:26:59 -07:00
|
|
|
|
2023-01-29 22:29:17 -03:30
|
|
|
/// A font
|
2022-11-15 12:26:59 -07:00
|
|
|
pub struct Font<'a> {
|
|
|
|
|
pub info: &'a fontdb::FaceInfo,
|
|
|
|
|
pub data: &'a [u8],
|
|
|
|
|
pub rustybuzz: rustybuzz::Face<'a>,
|
|
|
|
|
#[cfg(feature = "swash")]
|
|
|
|
|
pub swash: (u32, swash::CacheKey),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> Font<'a> {
|
|
|
|
|
pub fn new(info: &'a fontdb::FaceInfo) -> Option<Self> {
|
|
|
|
|
let data = match &info.source {
|
|
|
|
|
fontdb::Source::Binary(data) => data.deref().as_ref(),
|
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
|
fontdb::Source::File(path) => {
|
|
|
|
|
log::warn!("Unsupported fontdb Source::File('{}')", path.display());
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
|
fontdb::Source::SharedFile(_path, data) => data.deref().as_ref(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Some(Self {
|
|
|
|
|
info,
|
|
|
|
|
data,
|
|
|
|
|
rustybuzz: rustybuzz::Face::from_slice(data, info.index)?,
|
|
|
|
|
#[cfg(feature = "swash")]
|
|
|
|
|
swash: {
|
|
|
|
|
let swash = swash::FontRef::from_index(data, info.index as usize)?;
|
|
|
|
|
(swash.offset, swash.key)
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "swash")]
|
|
|
|
|
pub fn as_swash(&self) -> swash::FontRef {
|
|
|
|
|
swash::FontRef {
|
|
|
|
|
data: self.data,
|
|
|
|
|
offset: self.swash.0,
|
|
|
|
|
key: self.swash.1,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|