Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_outline_commands_uncached #340

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/swash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading