Add get_outline_commands_uncached

This commit is contained in:
Taj Pereira 2024-12-22 06:20:14 +09:00 committed by Jeremy Soller
parent 829a59bd95
commit 81c9666eaa

View file

@ -65,7 +65,7 @@ fn swash_outline_commands(
font_system: &mut FontSystem,
context: &mut ScaleContext,
cache_key: CacheKey,
) -> Option<Vec<swash::zeno::Command>> {
) -> Option<Box<[swash::zeno::Command]>> {
use swash::zeno::PathData as _;
let font = match font_system.get_font(cache_key.font_id) {
@ -98,7 +98,7 @@ fn swash_outline_commands(
pub struct SwashCache {
context: ScaleContext,
pub image_cache: HashMap<CacheKey, Option<SwashImage>>,
pub outline_command_cache: HashMap<CacheKey, Option<Vec<swash::zeno::Command>>>,
pub outline_command_cache: HashMap<CacheKey, Option<Box<[swash::zeno::Command]>>>,
}
impl fmt::Debug for SwashCache {
@ -137,6 +137,7 @@ impl SwashCache {
.or_insert_with(|| swash_image(font_system, &mut self.context, cache_key))
}
/// Creates outline commands
pub fn get_outline_commands(
&mut self,
font_system: &mut FontSystem,
@ -148,6 +149,15 @@ impl SwashCache {
.as_deref()
}
/// Creates outline commands, without caching results
pub fn get_outline_commands_uncached(
&mut self,
font_system: &mut FontSystem,
cache_key: CacheKey,
) -> Option<Box<[swash::zeno::Command]>> {
swash_outline_commands(font_system, &mut self.context, cache_key)
}
/// Enumerate pixels in an Image, use `with_image` for better performance
pub fn with_pixels<F: FnMut(i32, i32, Color)>(
&mut self,