diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-01-29 20:44:33 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-01-29 20:44:33 +0100 |
| commit | d9d2c021d62abb4fe6d12b994334bd211e462cde (patch) | |
| tree | ee82597e2ce1237a30a40054ac65c8aaf9ea1e4a | |
| parent | 5f4f507ecf02e580bac2d62253ebf4a6d0a44783 (diff) | |
Fix inline math bounding box
| -rw-r--r-- | library/src/math/mod.rs | 15 | ||||
| -rw-r--r-- | tests/ref/math/simple.png | bin | 8333 -> 8331 bytes | |||
| -rw-r--r-- | tests/ref/math/syntax.png | bin | 54019 -> 53967 bytes |
3 files changed, 14 insertions, 1 deletions
diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index 65baf7ac..f24b8078 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -223,7 +223,20 @@ impl Layout for FormulaNode { }; let mut ctx = MathContext::new(vt, styles, regions, &font, self.block); - let frame = ctx.layout_frame(self)?; + let mut frame = ctx.layout_frame(self)?; + + if !self.block { + let slack = styles.get(ParNode::LEADING) * 0.7; + let top_edge = styles.get(TextNode::TOP_EDGE).resolve(styles, font.metrics()); + let bottom_edge = + -styles.get(TextNode::BOTTOM_EDGE).resolve(styles, font.metrics()); + + let ascent = top_edge.max(frame.ascent() - slack); + let descent = bottom_edge.max(frame.descent() - slack); + frame.translate(Point::with_y(ascent - frame.baseline())); + frame.size_mut().y = ascent + descent; + } + Ok(Fragment::frame(frame)) } } diff --git a/tests/ref/math/simple.png b/tests/ref/math/simple.png Binary files differindex a0a864af..60597c9e 100644 --- a/tests/ref/math/simple.png +++ b/tests/ref/math/simple.png diff --git a/tests/ref/math/syntax.png b/tests/ref/math/syntax.png Binary files differindex 2f0a40b6..54ec856d 100644 --- a/tests/ref/math/syntax.png +++ b/tests/ref/math/syntax.png |
