From df6e347bc55bdcbf370645442290198c0bcdd3fe Mon Sep 17 00:00:00 2001 From: Leedehai <18319900+Leedehai@users.noreply.github.com> Date: Tue, 4 Jun 2024 11:30:43 -0400 Subject: [PATCH] Align point and linebreak should not increase math row height (#4306) --- crates/typst/src/math/row.rs | 16 ++++++++++++++-- ...-4187-alignment-point-affects-row-height.png | Bin 0 -> 282 bytes tests/suite/math/equation.typ | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/ref/issue-4187-alignment-point-affects-row-height.png diff --git a/crates/typst/src/math/row.rs b/crates/typst/src/math/row.rs index 0681752ac..cb909b0bc 100644 --- a/crates/typst/src/math/row.rs +++ b/crates/typst/src/math/row.rs @@ -117,11 +117,19 @@ impl MathRun { } pub fn ascent(&self) -> Abs { - self.iter().map(MathFragment::ascent).max().unwrap_or_default() + self.iter() + .filter(|e| affects_row_height(e)) + .map(|e| e.ascent()) + .max() + .unwrap_or_default() } pub fn descent(&self) -> Abs { - self.iter().map(MathFragment::descent).max().unwrap_or_default() + self.iter() + .filter(|e| affects_row_height(e)) + .map(|e| e.descent()) + .max() + .unwrap_or_default() } pub fn class(&self) -> MathClass { @@ -386,3 +394,7 @@ impl MathRunFrameBuilder { frame } } + +fn affects_row_height(fragment: &MathFragment) -> bool { + !matches!(fragment, MathFragment::Align | MathFragment::Linebreak) +} diff --git a/tests/ref/issue-4187-alignment-point-affects-row-height.png b/tests/ref/issue-4187-alignment-point-affects-row-height.png new file mode 100644 index 0000000000000000000000000000000000000000..63a5768b7c41a90ca76d04d0fc7ae7beebdc23cc GIT binary patch literal 282 zcmeAS@N?(olHy`uVBq!ia0vp^6+o=Z0VEh4d_H&qsfV5}jv*Ddl7HAcG$dYm6xi*q zE4Q@*!Z?=nabcK1#_nBwKK^@t|Ns9n%wWd`R-e-Qvb?WA3e_$>+MTdr*~UDn8I7ja zcVn-HSpU^y3ON6$IIP^dI-#veQzZLb#Qog44#M5Lz23FS9Lp_q|9SU7vdPAZu=kOB zcbXSO+0;JD{A+2RnfP(-&hE4|$KO7lT`cB*-=S1~G2q#J{a=+?ZsP}P@i~;F*9&Z V>te2)>SYV^w5O||%Q~loCIDKDdKLfx literal 0 HcmV?d00001 diff --git a/tests/suite/math/equation.typ b/tests/suite/math/equation.typ index e7ae677e0..2345de549 100644 --- a/tests/suite/math/equation.typ +++ b/tests/suite/math/equation.typ @@ -256,6 +256,16 @@ $ q &= sum_k ln A \ ], ) +--- issue-4187-alignment-point-affects-row-height --- +// In this bug, a row of "-" only should have a very small height; but +// after adding an alignment point "&", the row gains a larger height. +// We need to test alignment point "&" does not affect a row's height. +#box($ - - $, fill: silver) +#box($ - - $, fill: silver) \ +#box($ a \ - - $, fill: silver) +#box($ &- - \ &a $, fill: silver) +#box($ &a \ &- - $, fill: silver) + --- issue-numbering-hint --- // In this bug, the hint and error messages for an equation // being reference mentioned that it was a "heading" and was