mirror of
https://github.com/typst/typst
synced 2025-06-29 00:32:53 +08:00
Short-circuit on None's when laying out AttachElem (#4546)
This commit is contained in:
parent
5c71ad7fe7
commit
98d98a4bfd
@ -261,8 +261,11 @@ fn layout_attachments(
|
|||||||
base: MathFragment,
|
base: MathFragment,
|
||||||
[tl, t, tr, bl, b, br]: [Option<MathFragment>; 6],
|
[tl, t, tr, bl, b, br]: [Option<MathFragment>; 6],
|
||||||
) -> SourceResult<()> {
|
) -> SourceResult<()> {
|
||||||
let (shift_up, shift_down) =
|
let (shift_up, shift_down) = if [&tl, &tr, &bl, &br].iter().all(|e| e.is_none()) {
|
||||||
compute_shifts_up_and_down(ctx, styles, &base, [&tl, &tr, &bl, &br]);
|
(Abs::zero(), Abs::zero())
|
||||||
|
} else {
|
||||||
|
compute_shifts_up_and_down(ctx, styles, &base, [&tl, &tr, &bl, &br])
|
||||||
|
};
|
||||||
|
|
||||||
let sup_delta = Abs::zero();
|
let sup_delta = Abs::zero();
|
||||||
let sub_delta = -base.italics_correction();
|
let sub_delta = -base.italics_correction();
|
||||||
@ -287,7 +290,11 @@ fn layout_attachments(
|
|||||||
let post_width_max =
|
let post_width_max =
|
||||||
(sup_delta + measure!(tr, width)).max(sub_delta + measure!(br, width));
|
(sup_delta + measure!(tr, width)).max(sub_delta + measure!(br, width));
|
||||||
|
|
||||||
let (center_frame, base_offset) = attach_top_and_bottom(ctx, styles, base, t, b);
|
let (center_frame, base_offset) = if t.is_none() && b.is_none() {
|
||||||
|
(base.into_frame(), Abs::zero())
|
||||||
|
} else {
|
||||||
|
attach_top_and_bottom(ctx, styles, base, t, b)
|
||||||
|
};
|
||||||
if [&tl, &bl, &tr, &br].iter().all(|&e| e.is_none()) {
|
if [&tl, &bl, &tr, &br].iter().all(|&e| e.is_none()) {
|
||||||
ctx.push(FrameFragment::new(ctx, styles, center_frame).with_class(base_class));
|
ctx.push(FrameFragment::new(ctx, styles, center_frame).with_class(base_class));
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user