Skip to content

Commit

Permalink
Fix text measurement when multiple font sizes are present (#15669)
Browse files Browse the repository at this point in the history
# Objective

- Fixes #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 #15622
  • Loading branch information
UkoeHB authored Oct 5, 2024
1 parent 7c03ca2 commit 0b5a360
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 0b5a360

Please sign in to comment.