summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeedehai <18319900+Leedehai@users.noreply.github.com>2024-06-04 11:30:43 -0400
committerGitHub <noreply@github.com>2024-06-04 15:30:43 +0000
commitdf6e347bc55bdcbf370645442290198c0bcdd3fe (patch)
tree7077226a019dcc51f65f1cc1716e577870441d7c
parent9adcd9a1f894b212e2757277781955a7d5b8bba8 (diff)
Align point and linebreak should not increase math row height (#4306)
-rw-r--r--crates/typst/src/math/row.rs16
-rw-r--r--tests/ref/issue-4187-alignment-point-affects-row-height.pngbin0 -> 282 bytes
-rw-r--r--tests/suite/math/equation.typ10
3 files changed, 24 insertions, 2 deletions
diff --git a/crates/typst/src/math/row.rs b/crates/typst/src/math/row.rs
index 0681752a..cb909b0b 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 00000000..63a5768b
--- /dev/null
+++ b/tests/ref/issue-4187-alignment-point-affects-row-height.png
Binary files differ
diff --git a/tests/suite/math/equation.typ b/tests/suite/math/equation.typ
index e7ae677e..2345de54 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