summaryrefslogtreecommitdiff
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
parent56159997b7a5866e0005f21ff3b6a5f4b9d3d6b3 (diff)
Expand the AttachElement frame so it encompasses its child center_frame (#2968)
-rw-r--r--crates/typst/src/layout/frame.rs8
-rw-r--r--crates/typst/src/math/attach.rs18
-rw-r--r--tests/ref/math/attach-p1.pngbin13779 -> 14112 bytes
-rw-r--r--tests/ref/visualize/gradient-math.pngbin38184 -> 38218 bytes
-rw-r--r--tests/typ/math/attach-p1.typ6
5 files changed, 20 insertions, 12 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 =
diff --git a/tests/ref/math/attach-p1.png b/tests/ref/math/attach-p1.png
index 41be1313..fa610729 100644
--- a/tests/ref/math/attach-p1.png
+++ b/tests/ref/math/attach-p1.png
Binary files differ
diff --git a/tests/ref/visualize/gradient-math.png b/tests/ref/visualize/gradient-math.png
index 825bfc15..6d9173b5 100644
--- a/tests/ref/visualize/gradient-math.png
+++ b/tests/ref/visualize/gradient-math.png
Binary files differ
diff --git a/tests/typ/math/attach-p1.typ b/tests/typ/math/attach-p1.typ
index 830ff26e..5564ec60 100644
--- a/tests/typ/math/attach-p1.typ
+++ b/tests/typ/math/attach-p1.typ
@@ -49,7 +49,11 @@ $pi_1(Y), a_f(x), a^zeta (x), a^abs(b)_sqrt(c) \
---
// Test associativity and scaling.
$ 1/(V^2^3^4^5),
- 1/attach(V, tl: attach(2, tl: attach(3, tl: attach(4, tl: 5)))),
+ frac(
+ attach(
+ limits(V), br: attach(2, br: 3), b: attach(limits(2), b: 3)),
+ attach(
+ limits(V), tl: attach(2, tl: 3), t: attach(limits(2), t: 3))),
attach(Omega,
tl: attach(2, tl: attach(3, tl: attach(4, tl: 5))),
tr: attach(2, tr: attach(3, tr: attach(4, tr: 5))),