From 96f695737174449cbd9efbf4954b676b9bb35056 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 11 Mar 2025 10:18:15 +0000 Subject: [PATCH] Fix `math.root` frame size (#6021) --- crates/typst-layout/src/math/root.rs | 8 +++++--- tests/ref/math-root-frame-size-index.png | Bin 0 -> 902 bytes tests/suite/math/root.typ | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 tests/ref/math-root-frame-size-index.png diff --git a/crates/typst-layout/src/math/root.rs b/crates/typst-layout/src/math/root.rs index a6b5c03d0..c7f41488e 100644 --- a/crates/typst-layout/src/math/root.rs +++ b/crates/typst-layout/src/math/root.rs @@ -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); } diff --git a/tests/ref/math-root-frame-size-index.png b/tests/ref/math-root-frame-size-index.png new file mode 100644 index 0000000000000000000000000000000000000000..41d4df2e9ea40429c2bc33bccec9afeb927374d9 GIT binary patch literal 902 zcmV;119|+3P)1i8`-j-*}=qYVapPY5}A+<9-Iye>Z(xM zl~(B}0~RTzPEs)|upmOI7*X&?#8TVRhm;nvwDxJ=wudKah$qu8UY_^u`?4HSYGnS{;D#1a#Z13Z08!n*r88 zzas*c%d^rT<0UE1JOsQ4dode$m!(q&;Aa3^<$?&f*+4}cYR##7;Cd##Ew+7a`3q3q zj5{YFd5g}kMZmv%;$_3I^tSmvu*09)y0jaMei%+R)&L`)V)qa>e1fc z2Z!?`SuiZcDeUolI|Cz#zv{>_#s+nI)O@E#*-!AVuF8y9xPF=HO9c;s;l5ed5Cal# zJQM-XSS{1c+2N4{WZU#$vzgMwTYy6V(_bL~j+7(0m@G-64*|Zzc8n(8gW26auJ!|q zjdfW8u&$koRrtk}k^rxg-nLTuSpE{Y{0+6h-6$Up34j|tu`)MAwi_3KcNUXdBOhTt z?FM%K+YRhf{N`?fyIRXy5#7cX6OH$!!PEDMC|S1D}D$A#-5Jy-q_ zeAVIOc$~Tus7*}XKYL?T;y`w#qi1hI9Qy({-ZS8ZI`&n|DVVXxIZ z#cU_6HUNsg4Xn1-Gyn++s8)cR6%-i`??Jl2bjdn@gn^kO=VV3^sPiheeB%&fcht}5a3%&k>Ms!v}_2LOAUTtXCV2KT#oUK z`sUa(U;t_?d}b;#EZbcz<3Qz)0OO7-Cm!eENp(AWUQGZ|`{~+@pszX@