From bbb9ed07ffe8a2a0ea0a232f6cfc52f82f7f7afe Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 10 Mar 2021 10:20:01 +0100 Subject: =?UTF-8?q?Better=20line=20spacing=20calculations=20=E2=86=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Only add line spacing between lines. Previously, line spacing was added below every line, making `#box[word]` higher than just `word`. - Compute box height of text as `ascender - descender` so that the full word is contained in the box. --- src/layout/par.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/layout') diff --git a/src/layout/par.rs b/src/layout/par.rs index 7d876fc1..45494dec 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -163,13 +163,17 @@ impl<'a> ParLayouter<'a> { output.push_frame(pos, frame); } + // Add line spacing, but only between lines. + if !self.lines.is_empty() { + self.lines_size.main += self.par.line_spacing; + *self.areas.current.get_mut(self.main) -= self.par.line_spacing; + } + // Update metrics of the whole paragraph. self.lines.push((self.lines_size.main, output, self.line_ruler)); self.lines_size.main += full_size.main; - self.lines_size.main += self.par.line_spacing; self.lines_size.cross = self.lines_size.cross.max(full_size.cross); *self.areas.current.get_mut(self.main) -= full_size.main; - *self.areas.current.get_mut(self.main) -= self.par.line_spacing; // Reset metrics for the single line. self.line_size = Gen::ZERO; -- cgit v1.2.3