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

Fix: Font size limit to prevent panic #5139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Update fonts.rs
  • Loading branch information
rustbasic committed Sep 20, 2024
commit d67518e3834e612fc673d7b0e837d10a6bf92683
7 changes: 4 additions & 3 deletions crates/epaint/src/text/fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,18 +620,19 @@ impl FontsImpl {

/// Get the right font implementation from size and [`FontFamily`].
pub fn font(&mut self, font_id: &FontId) -> &mut Font {
let FontId { size, family } = font_id;
let FontId { mut size, family } = font_id;
size = size.at_least(0.1).at_most(2048.0);

self.sized_family
.entry((OrderedFloat(*size), family.clone()))
.entry((OrderedFloat(size), family.clone()))
.or_insert_with(|| {
let fonts = &self.definitions.families.get(family);
let fonts = fonts
.unwrap_or_else(|| panic!("FontFamily::{family:?} is not bound to any fonts"));

let fonts: Vec<Arc<FontImpl>> = fonts
.iter()
.map(|font_name| self.font_impl_cache.font_impl(*size, font_name))
.map(|font_name| self.font_impl_cache.font_impl(size, font_name))
.collect();

Font::new(fonts)
Expand Down
Loading