From 2858c09b6e50e727250e037114f118a19d34514d Mon Sep 17 00:00:00 2001 From: David Wendt Date: Tue, 2 Jun 2020 19:27:10 -0400 Subject: [PATCH] Only apply leading adjustment on newlines. This results in ALL height adjustments being off by 2px, regardless of leading or font size. Tantalizing! --- core/src/html/layout.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/src/html/layout.rs b/core/src/html/layout.rs index 68ed39f12..39676289e 100644 --- a/core/src/html/layout.rs +++ b/core/src/html/layout.rs @@ -88,7 +88,18 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> { self.font .map(|f| f.get_leading_for_height(self.max_font_size)) .unwrap_or_else(|| Twips::new(0)), - ) + Twips::from_pixels(self.current_line_span.leading) + ) + } + + /// Calculate the line-to-line leading present on ths line, including the + /// font-leading above. + fn line_leading_adjustment(&self) -> Twips { + round_down_to_pixel( + self.font + .map(|f| f.get_leading_for_height(self.max_font_size)) + .unwrap_or_else(|| Twips::new(0)) + + Twips::from_pixels(self.current_line_span.leading), + ) } /// Apply all indents and alignment to the current line, if necessary. @@ -180,7 +191,7 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> { self.cursor.set_x(Twips::from_pixels(0.0)); self.cursor += ( Twips::from_pixels(0.0), - self.max_font_size + self.font_leading_adjustment(), + self.max_font_size + self.line_leading_adjustment(), ) .into();