Revert "Make FontSystem not self-referencing and update fontdb and rustybuzz"

This commit is contained in:
Jeremy Soller 2023-03-02 18:16:57 -07:00 committed by GitHub
parent b6398a2d57
commit eca804c732
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 179 additions and 225 deletions

View file

@ -4,18 +4,12 @@ use core::ops::Deref;
pub(crate) mod fallback;
pub use self::matches::*;
mod matches;
pub use self::system::*;
mod system;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(not(feature = "swash"), repr(transparent))]
/// Identifies a [`Font`] in a [`FontSystem`]
pub struct FontKey {
pub id: fontdb::ID,
#[cfg(feature = "swash")]
pub swash: (u32, swash::CacheKey),
}
/// A font
pub struct Font<'a> {
pub info: &'a fontdb::FaceInfo,
@ -50,48 +44,6 @@ impl<'a> Font<'a> {
})
}
pub fn from_key(db: &'a fontdb::Database, key: FontKey) -> Option<Self> {
let info = db.face(key.id)?;
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: key.swash,
})
}
pub fn key(&self) -> FontKey {
FontKey {
id: self.info.id,
#[cfg(feature = "swash")]
swash: self.swash,
}
}
pub fn name(&self) -> &str {
if let Some((name, _)) = self.info.families.first() {
name
} else {
&self.info.post_script_name
}
}
pub fn contains_family(&self, family: &str) -> bool {
self.info.families.iter().any(|(name, _)| name == family)
}
#[cfg(feature = "swash")]
pub fn as_swash(&self) -> swash::FontRef {
swash::FontRef {