From ef429fbea6e39efcfdc58fdd8a2fe365fd5314d9 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Mon, 4 Sep 2023 02:58:54 -0400 Subject: [PATCH 1/4] Ensure LineHeight > 0.0 for the WGPU renderer --- wgpu/src/text.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index fb13545da7..08a32b5ed0 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -96,7 +96,8 @@ impl Pipeline { section .line_height .to_absolute(Pixels(section.size)), - ), + ) + .max(f32::MIN_POSITIVE), font: section.font, bounds: Size { width: section.bounds.width, @@ -238,7 +239,8 @@ impl Pipeline { ) -> Size { let mut cache = self.cache.borrow_mut(); - let line_height = f32::from(line_height.to_absolute(Pixels(size))); + let line_height = f32::from(line_height.to_absolute(Pixels(size))) + .max(f32::MIN_POSITIVE); let (_, entry) = cache.allocate( &mut self.font_system.borrow_mut(), @@ -269,7 +271,8 @@ impl Pipeline { ) -> Option { let mut cache = self.cache.borrow_mut(); - let line_height = f32::from(line_height.to_absolute(Pixels(size))); + let line_height = f32::from(line_height.to_absolute(Pixels(size))) + .max(f32::MIN_POSITIVE); let (_, entry) = cache.allocate( &mut self.font_system.borrow_mut(), From 20681b4777a1954e6b7f659d5bc1817f7924f40d Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Mon, 4 Sep 2023 21:03:16 -0400 Subject: [PATCH 2/4] Ensure LineHeight is always > 0.0 for tiny skia. --- tiny_skia/src/text.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs index 08fde4bf25..9b94921858 100644 --- a/tiny_skia/src/text.rs +++ b/tiny_skia/src/text.rs @@ -54,7 +54,8 @@ impl Pipeline { pixels: &mut tiny_skia::PixmapMut<'_>, clip_mask: Option<&tiny_skia::Mask>, ) { - let line_height = f32::from(line_height.to_absolute(Pixels(size))); + let line_height = f32::from(line_height.to_absolute(Pixels(size))) + .max(f32::MIN_POSITIVE); let font_system = self.font_system.get_mut(); let key = Key { @@ -134,7 +135,8 @@ impl Pipeline { ) -> Size { let mut measurement_cache = self.cache.borrow_mut(); - let line_height = f32::from(line_height.to_absolute(Pixels(size))); + let line_height = f32::from(line_height.to_absolute(Pixels(size))) + .max(f32::MIN_POSITIVE); let (_, entry) = measurement_cache.allocate( &mut self.font_system.borrow_mut(), @@ -164,7 +166,8 @@ impl Pipeline { ) -> Option { let mut measurement_cache = self.cache.borrow_mut(); - let line_height = f32::from(line_height.to_absolute(Pixels(size))); + let line_height = f32::from(line_height.to_absolute(Pixels(size))) + .max(f32::MIN_POSITIVE); let (_, entry) = measurement_cache.allocate( &mut self.font_system.borrow_mut(), @@ -405,7 +408,10 @@ impl Cache { } if let hash_map::Entry::Vacant(entry) = self.entries.entry(hash) { - let metrics = cosmic_text::Metrics::new(key.size, key.size * 1.2); + let metrics = cosmic_text::Metrics::new( + key.size, + (key.size * 1.2).max(f32::MIN_POSITIVE), + ); let mut buffer = cosmic_text::Buffer::new(font_system, metrics); buffer.set_size( From bdf18554feadb631fdae5b427ac7a92a5546ade1 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Mon, 4 Sep 2023 23:47:44 -0400 Subject: [PATCH 3/4] Check LineHeight > 0.0 before allocating text --- tiny_skia/src/text.rs | 13 +++++-------- wgpu/src/text.rs | 14 +++++++------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs index 9b94921858..24b17662ff 100644 --- a/tiny_skia/src/text.rs +++ b/tiny_skia/src/text.rs @@ -54,8 +54,7 @@ impl Pipeline { pixels: &mut tiny_skia::PixmapMut<'_>, clip_mask: Option<&tiny_skia::Mask>, ) { - let line_height = f32::from(line_height.to_absolute(Pixels(size))) - .max(f32::MIN_POSITIVE); + let line_height = f32::from(line_height.to_absolute(Pixels(size))); let font_system = self.font_system.get_mut(); let key = Key { @@ -135,8 +134,7 @@ impl Pipeline { ) -> Size { let mut measurement_cache = self.cache.borrow_mut(); - let line_height = f32::from(line_height.to_absolute(Pixels(size))) - .max(f32::MIN_POSITIVE); + let line_height = f32::from(line_height.to_absolute(Pixels(size))); let (_, entry) = measurement_cache.allocate( &mut self.font_system.borrow_mut(), @@ -166,8 +164,7 @@ impl Pipeline { ) -> Option { let mut measurement_cache = self.cache.borrow_mut(); - let line_height = f32::from(line_height.to_absolute(Pixels(size))) - .max(f32::MIN_POSITIVE); + let line_height = f32::from(line_height.to_absolute(Pixels(size))); let (_, entry) = measurement_cache.allocate( &mut self.font_system.borrow_mut(), @@ -409,8 +406,8 @@ impl Cache { if let hash_map::Entry::Vacant(entry) = self.entries.entry(hash) { let metrics = cosmic_text::Metrics::new( - key.size, - (key.size * 1.2).max(f32::MIN_POSITIVE), + key.line_height, + (key.line_height * 1.2).max(f32::MIN_POSITIVE), ); let mut buffer = cosmic_text::Buffer::new(font_system, metrics); diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 08a32b5ed0..9c42be0e82 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -96,8 +96,7 @@ impl Pipeline { section .line_height .to_absolute(Pixels(section.size)), - ) - .max(f32::MIN_POSITIVE), + ), font: section.font, bounds: Size { width: section.bounds.width, @@ -239,8 +238,7 @@ impl Pipeline { ) -> Size { let mut cache = self.cache.borrow_mut(); - let line_height = f32::from(line_height.to_absolute(Pixels(size))) - .max(f32::MIN_POSITIVE); + let line_height = f32::from(line_height.to_absolute(Pixels(size))); let (_, entry) = cache.allocate( &mut self.font_system.borrow_mut(), @@ -271,8 +269,7 @@ impl Pipeline { ) -> Option { let mut cache = self.cache.borrow_mut(); - let line_height = f32::from(line_height.to_absolute(Pixels(size))) - .max(f32::MIN_POSITIVE); + let line_height = f32::from(line_height.to_absolute(Pixels(size))); let (_, entry) = cache.allocate( &mut self.font_system.borrow_mut(), @@ -417,7 +414,10 @@ impl Cache { } if let hash_map::Entry::Vacant(entry) = self.entries.entry(hash) { - let metrics = glyphon::Metrics::new(key.size, key.line_height); + let metrics = glyphon::Metrics::new( + key.size, + key.line_height.max(f32::MIN_POSITIVE), + ); let mut buffer = glyphon::Buffer::new(font_system, metrics); buffer.set_size( From cee0ed64694e06eb3061acc1abd76deded3e0648 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Tue, 5 Sep 2023 20:45:27 -0400 Subject: [PATCH 4/4] Use the correct text size and height in tiny_skia --- tiny_skia/src/text.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs index 24b17662ff..306b400a55 100644 --- a/tiny_skia/src/text.rs +++ b/tiny_skia/src/text.rs @@ -406,8 +406,8 @@ impl Cache { if let hash_map::Entry::Vacant(entry) = self.entries.entry(hash) { let metrics = cosmic_text::Metrics::new( - key.line_height, - (key.line_height * 1.2).max(f32::MIN_POSITIVE), + key.size, + key.line_height.max(f32::MIN_POSITIVE), ); let mut buffer = cosmic_text::Buffer::new(font_system, metrics);