From 0b5a3605852d89f29795f32c9abfe2b9aae90033 Mon Sep 17 00:00:00 2001 From: UkoeHB <37489173+UkoeHB@users.noreply.github.com> Date: Sat, 5 Oct 2024 17:46:37 -0500 Subject: [PATCH] Fix text measurement when multiple font sizes are present (#15669) # Objective - Fixes https://github.com/bevyengine/bevy/issues/15659 ## Solution - Add up line heights to get text block height instead of using `Metrics`, which only records the largest line height. ## Testing - [x] Fixed issue shown in https://github.com/bevyengine/bevy/pull/15622 --- crates/bevy_text/src/pipeline.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index d435d25db2..e63cd2d76d 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -455,15 +455,13 @@ fn get_attrs<'a>( /// Calculate the size of the text area for the given buffer. fn buffer_dimensions(buffer: &Buffer) -> Vec2 { - let width = buffer + let (width, height) = buffer .layout_runs() - .map(|run| run.line_w) - .reduce(f32::max) - .unwrap_or(0.0); - let line_height = buffer.metrics().line_height.ceil(); - let height = buffer.layout_runs().count() as f32 * line_height; + .map(|run| (run.line_w, run.line_height)) + .reduce(|(w1, h1), (w2, h2)| (w1.max(w2), h1 + h2)) + .unwrap_or((0.0, 0.0)); - Vec2::new(width.ceil(), height).ceil() + Vec2::new(width, height).ceil() } /// Discards stale data cached in `FontSystem`.