mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Fix math.root
frame size (#6021)
This commit is contained in:
parent
3650859ae8
commit
96f6957371
@ -85,14 +85,15 @@ pub fn layout_root(
|
||||
ascent.set_max(shift_up + index.ascent());
|
||||
}
|
||||
|
||||
let radicand_x = sqrt_offset + sqrt.width();
|
||||
let sqrt_x = sqrt_offset.max(Abs::zero());
|
||||
let radicand_x = sqrt_x + sqrt.width();
|
||||
let radicand_y = ascent - radicand.ascent();
|
||||
let width = radicand_x + radicand.width();
|
||||
let size = Size::new(width, ascent + descent);
|
||||
|
||||
// The extra "- thickness" comes from the fact that the sqrt is placed
|
||||
// in `push_frame` with respect to its top, not its baseline.
|
||||
let sqrt_pos = Point::new(sqrt_offset, radicand_y - gap - thickness);
|
||||
let sqrt_pos = Point::new(sqrt_x, radicand_y - gap - thickness);
|
||||
let line_pos = Point::new(radicand_x, radicand_y - gap - (thickness / 2.0));
|
||||
let radicand_pos = Point::new(radicand_x, radicand_y);
|
||||
|
||||
@ -100,7 +101,8 @@ pub fn layout_root(
|
||||
frame.set_baseline(ascent);
|
||||
|
||||
if let Some(index) = index {
|
||||
let index_pos = Point::new(kern_before, ascent - index.ascent() - shift_up);
|
||||
let index_x = -sqrt_offset.min(Abs::zero()) + kern_before;
|
||||
let index_pos = Point::new(index_x, ascent - index.ascent() - shift_up);
|
||||
frame.push_frame(index_pos, index);
|
||||
}
|
||||
|
||||
|
BIN
tests/ref/math-root-frame-size-index.png
Normal file
BIN
tests/ref/math-root-frame-size-index.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 902 B |
@ -44,3 +44,9 @@ $ root(2, x) quad
|
||||
$ √2^3 = sqrt(2^3) $
|
||||
$ √(x+y) quad ∛x quad ∜x $
|
||||
$ (√2+3) = (sqrt(2)+3) $
|
||||
|
||||
--- math-root-frame-size-index ---
|
||||
// Test size of final frame when there is an index.
|
||||
$ a root(, 3) & a root(., 3) \
|
||||
a sqrt(3) & a root(2, 3) \
|
||||
a root(#h(-1em), 3) & a root(123, 3) $
|
||||
|
Loading…
x
Reference in New Issue
Block a user