Do not require lifetime for swash fontref

This commit is contained in:
Jeremy Soller 2022-10-25 18:16:14 -06:00
parent 525c4efaa5
commit 3e8e28f0b3
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
2 changed files with 15 additions and 3 deletions

View file

@ -8,7 +8,7 @@ pub struct Font<'a> {
pub index: u32, pub index: u32,
pub rustybuzz: rustybuzz::Face<'a>, pub rustybuzz: rustybuzz::Face<'a>,
#[cfg(feature = "swash")] #[cfg(feature = "swash")]
pub swash: swash::FontRef<'a>, pub swash: (u32, swash::CacheKey),
} }
impl<'a> Font<'a> { impl<'a> Font<'a> {
@ -28,7 +28,19 @@ impl<'a> Font<'a> {
index: info.index, index: info.index,
rustybuzz: rustybuzz::Face::from_slice(data, info.index)?, rustybuzz: rustybuzz::Face::from_slice(data, info.index)?,
#[cfg(feature = "swash")] #[cfg(feature = "swash")]
swash: swash::FontRef::from_index(data, info.index as usize)?, 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,
}
}
} }

View file

@ -36,7 +36,7 @@ impl SwashCache {
// Build the scaler // Build the scaler
let mut scaler = self.context let mut scaler = self.context
.builder(font.swash) .builder(font.as_swash())
.size(cache_key.font_size as f32) .size(cache_key.font_size as f32)
.hint(true) .hint(true)
.build(); .build();