diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-03-10 10:20:01 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-03-10 10:20:01 +0100 |
| commit | bbb9ed07ffe8a2a0ea0a232f6cfc52f82f7f7afe (patch) | |
| tree | 2b106b63e104652b66efc74a0ffa3080a8b0a134 /src/layout | |
| parent | b2b8d37ce03de60582230e03c03efa356b6f31d3 (diff) | |
Better line spacing calculations ↕
- 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.
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/par.rs | 8 |
1 files changed, 6 insertions, 2 deletions
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; |
