summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeedehai <18319900+Leedehai@users.noreply.github.com>2024-08-15 16:08:40 -0400
committerGitHub <noreply@github.com>2024-08-15 20:08:40 +0000
commitd221a89a40ba504408468d8f427ce8933e332a6f (patch)
treee5f3fe372777c1740190f2b9fdb988021107f6d4
parentc43997de0a4fa958bc6bdfd5c29a47e1ba14800d (diff)
Adjust the baseline of root radicand frame (#4736)
-rw-r--r--crates/typst/src/math/root.rs16
-rw-r--r--crates/typst/src/math/row.rs2
-rw-r--r--tests/ref/math-root-large-body.pngbin1549 -> 1831 bytes
-rw-r--r--tests/suite/math/root.typ1
4 files changed, 16 insertions, 3 deletions
diff --git a/crates/typst/src/math/root.rs b/crates/typst/src/math/root.rs
index 6a760445..66707c59 100644
--- a/crates/typst/src/math/root.rs
+++ b/crates/typst/src/math/root.rs
@@ -70,8 +70,20 @@ fn layout(
let raise_factor = percent!(ctx, radical_degree_bottom_raise_percent);
// Layout radicand.
- let cramped = style_cramped();
- let radicand = ctx.layout_into_frame(radicand, styles.chain(&cramped))?;
+ let radicand = {
+ let cramped = style_cramped();
+ let styles = styles.chain(&cramped);
+ let run = ctx.layout_into_run(radicand, styles)?;
+ let multiline = run.is_multiline();
+ let mut radicand = run.into_fragment(ctx, styles).into_frame();
+ if multiline {
+ // Align the frame center line with the math axis.
+ radicand.set_baseline(
+ radicand.height() / 2.0 + scaled!(ctx, styles, axis_height),
+ );
+ }
+ radicand
+ };
// Layout root symbol.
let target = radicand.height() + thickness + gap;
diff --git a/crates/typst/src/math/row.rs b/crates/typst/src/math/row.rs
index 60afe64e..cafffdc5 100644
--- a/crates/typst/src/math/row.rs
+++ b/crates/typst/src/math/row.rs
@@ -353,7 +353,7 @@ impl MathRun {
items
}
- fn is_multiline(&self) -> bool {
+ pub fn is_multiline(&self) -> bool {
self.iter().any(|frag| matches!(frag, MathFragment::Linebreak))
}
}
diff --git a/tests/ref/math-root-large-body.png b/tests/ref/math-root-large-body.png
index b8d9edfb..20363647 100644
--- a/tests/ref/math-root-large-body.png
+++ b/tests/ref/math-root-large-body.png
Binary files differ
diff --git a/tests/suite/math/root.typ b/tests/suite/math/root.typ
index a690802e..df339fa8 100644
--- a/tests/suite/math/root.typ
+++ b/tests/suite/math/root.typ
@@ -30,6 +30,7 @@ $ sqrt([|x|]^2 + [|y|]^2) < [|z|] $
$ v = sqrt((1/2) / (4/5))
= root(3, (1/2/3) / (4/5/6))
= root(4, ((1/2) / (3/4)) / ((1/2) / (3/4))) $
+$ v = sqrt(a +\ b) $
--- math-root-large-index ---
// Test large index.