diff options
| author | Leedehai <18319900+Leedehai@users.noreply.github.com> | 2024-05-22 13:04:46 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-22 17:04:46 +0000 |
| commit | 53c306e32cd9622f7f2af66e08b6846712e78633 (patch) | |
| tree | 69104ac3b65e2929196bf3c95c7ceec0e11c369c /crates | |
| parent | 90ce65adca67d2bee68df2e2d53a0550f1d661ea (diff) | |
Fix equation resizing when adding the equation number (#4179)
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst/src/math/equation.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/crates/typst/src/math/equation.rs b/crates/typst/src/math/equation.rs index 947f01f2..d6a8d4c7 100644 --- a/crates/typst/src/math/equation.rs +++ b/crates/typst/src/math/equation.rs @@ -466,25 +466,33 @@ fn resize_equation( if matches!(number_align.y, FixedAlignment::Center if is_multiline) { // In this case, the center lines (not baselines) of the number frame // and the equation frame shall be aligned. - let height = equation.height().max(number.height()); return equation.resize( - Size::new(width, height), + Size::new(width, equation.height().max(number.height())), Axes::<FixedAlignment>::new(equation_align, FixedAlignment::Center), ); } let excess_above = Abs::zero().max({ - let (.., baseline) = first; - number.baseline() - baseline + if !is_multiline || matches!(number_align.y, FixedAlignment::Start) { + let (.., baseline) = first; + number.baseline() - baseline + } else { + Abs::zero() + } }); let excess_below = Abs::zero().max({ - let (size, .., baseline) = last; - (number.height() - number.baseline()) - (size.y - baseline) + if !is_multiline || matches!(number_align.y, FixedAlignment::End) { + let (size, .., baseline) = last; + (number.height() - number.baseline()) - (size.y - baseline) + } else { + Abs::zero() + } }); - let height = equation.height() + excess_above + excess_below; + // The vertical expansion is asymmetric on the top and bottom edges, so we + // first align at the top then translate the content downward later. let resizing_offset = equation.resize( - Size::new(width, height), + Size::new(width, equation.height() + excess_above + excess_below), Axes::<FixedAlignment>::new(equation_align, FixedAlignment::Start), ); equation.translate(Point::with_y(excess_above)); |
