Fix precision issue with line heights (#33438)

When computing the ascent and descent in an inline formatting context,
we weren't taking into account that app units have precision limitations.
Therefore, in some cases we were getting a line height that was slightly
taller than the value specified in `line-height`.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Oriol Brufau 2024-09-13 18:56:14 +02:00 committed by GitHub
parent a76daaf04c
commit fa8752df6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 5 additions and 41 deletions

View file

@ -1815,8 +1815,12 @@ impl InlineContainerState {
ascent = font_metrics_of_first_font.ascent;
descent = font_metrics_of_first_font.descent;
let half_leading = (line_height - (ascent + descent)).scale_by(0.5);
// We want the sum of `ascent` and `descent` to equal `line_height`.
// If we just add `half_leading` to both, then we may not get `line_height`
// due to precision limitations of `Au`. Instead, we set `descent` to
// the value that will guarantee the correct sum.
ascent += half_leading;
descent += half_leading;
descent = line_height - ascent;
}
LineBlockSizes {