Skip to content

Commit

Permalink
Clamp font size to between 0.1 and 2048 (emilk#5139)
Browse files Browse the repository at this point in the history
Fix: Font size limit to prevent panic
  • Loading branch information
rustbasic authored and hacknus committed Oct 30, 2024
1 parent bf0ee24 commit 3da4760
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit 3da4760

Please sign in to comment.