summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLeedehai <18319900+Leedehai@users.noreply.github.com>2023-12-18 04:19:55 -0800
committerGitHub <noreply@github.com>2023-12-18 13:19:55 +0100
commit47bb32809a28325d85ed4eb4d1c8750a6baf4121 (patch)
treeaa1671e6d9f6236b84801b9e45c6f56b063b9908 /crates
parent56159997b7a5866e0005f21ff3b6a5f4b9d3d6b3 (diff)
Expand the AttachElement frame so it encompasses its child center_frame (#2968)
Diffstat (limited to 'crates')
-rw-r--r--crates/typst/src/layout/frame.rs8
-rw-r--r--crates/typst/src/math/attach.rs18
2 files changed, 15 insertions, 11 deletions
diff --git a/crates/typst/src/layout/frame.rs b/crates/typst/src/layout/frame.rs
index d06cd23d..af1fd5d1 100644
--- a/crates/typst/src/layout/frame.rs
+++ b/crates/typst/src/layout/frame.rs
@@ -365,13 +365,13 @@ impl Frame {
/// Tools for debugging.
impl Frame {
/// Add a full size aqua background and a red baseline for debugging.
- pub fn debug(mut self) -> Self {
- self.debug_in_place();
+ pub fn mark_box(mut self) -> Self {
+ self.mark_box_in_place();
self
}
- /// Debug in place.
- pub fn debug_in_place(&mut self) {
+ /// Debug in place. Add a full size aqua background and a red baseline for debugging.
+ pub fn mark_box_in_place(&mut self) {
self.insert(
0,
Point::zero(),
diff --git a/crates/typst/src/math/attach.rs b/crates/typst/src/math/attach.rs
index 71074edc..b641c878 100644
--- a/crates/typst/src/math/attach.rs
+++ b/crates/typst/src/math/attach.rs
@@ -243,12 +243,12 @@ fn layout_attachments(
(base.width(), base.ascent(), base.descent());
let base_class = base.class().unwrap_or(MathClass::Normal);
- let ascent = base_ascent
+ let mut ascent = base_ascent
.max(shift_up + measure!(tr, ascent))
.max(shift_up + measure!(tl, ascent))
.max(shift_up + measure!(t, height));
- let descent = base_descent
+ let mut descent = base_descent
.max(shift_down + measure!(br, descent))
.max(shift_down + measure!(bl, descent))
.max(shift_down + measure!(b, height));
@@ -257,23 +257,27 @@ fn layout_attachments(
let pre_sub_width = measure!(bl, width);
let pre_width_dif = pre_sup_width - pre_sub_width; // Could be negative.
let pre_width_max = pre_sup_width.max(pre_sub_width);
- let post_max_width =
+ let post_width_max =
(sup_delta + measure!(tr, width)).max(sub_delta + measure!(br, width));
let (center_frame, base_offset) = attach_top_and_bottom(ctx, base, t, b);
- let base_pos =
- Point::new(sup_delta + pre_width_max, ascent - base_ascent - base_offset);
if [&tl, &bl, &tr, &br].iter().all(|&e| e.is_none()) {
ctx.push(FrameFragment::new(ctx, center_frame).with_class(base_class));
return Ok(());
}
+ ascent.set_max(center_frame.ascent());
+ descent.set_max(center_frame.descent());
+
let mut frame = Frame::soft(Size::new(
- pre_width_max + base_width + post_max_width + scaled!(ctx, space_after_script),
+ pre_width_max + base_width + post_width_max + scaled!(ctx, space_after_script),
ascent + descent,
));
frame.set_baseline(ascent);
- frame.push_frame(base_pos, center_frame);
+ frame.push_frame(
+ Point::new(sup_delta + pre_width_max, frame.ascent() - base_ascent - base_offset),
+ center_frame,
+ );
if let Some(tl) = tl {
let pos =