mirror of
https://github.com/typst/typst
synced 2025-05-26 06:55:28 +08:00
Expand the AttachElement frame so it encompasses its child center_frame (#2968)
This commit is contained in:
parent
56159997b7
commit
47bb32809a
@ -365,13 +365,13 @@ impl Frame {
|
|||||||
/// Tools for debugging.
|
/// Tools for debugging.
|
||||||
impl Frame {
|
impl Frame {
|
||||||
/// Add a full size aqua background and a red baseline for debugging.
|
/// Add a full size aqua background and a red baseline for debugging.
|
||||||
pub fn debug(mut self) -> Self {
|
pub fn mark_box(mut self) -> Self {
|
||||||
self.debug_in_place();
|
self.mark_box_in_place();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Debug in place.
|
/// Debug in place. Add a full size aqua background and a red baseline for debugging.
|
||||||
pub fn debug_in_place(&mut self) {
|
pub fn mark_box_in_place(&mut self) {
|
||||||
self.insert(
|
self.insert(
|
||||||
0,
|
0,
|
||||||
Point::zero(),
|
Point::zero(),
|
||||||
|
@ -243,12 +243,12 @@ fn layout_attachments(
|
|||||||
(base.width(), base.ascent(), base.descent());
|
(base.width(), base.ascent(), base.descent());
|
||||||
let base_class = base.class().unwrap_or(MathClass::Normal);
|
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!(tr, ascent))
|
||||||
.max(shift_up + measure!(tl, ascent))
|
.max(shift_up + measure!(tl, ascent))
|
||||||
.max(shift_up + measure!(t, height));
|
.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!(br, descent))
|
||||||
.max(shift_down + measure!(bl, descent))
|
.max(shift_down + measure!(bl, descent))
|
||||||
.max(shift_down + measure!(b, height));
|
.max(shift_down + measure!(b, height));
|
||||||
@ -257,23 +257,27 @@ fn layout_attachments(
|
|||||||
let pre_sub_width = measure!(bl, width);
|
let pre_sub_width = measure!(bl, width);
|
||||||
let pre_width_dif = pre_sup_width - pre_sub_width; // Could be negative.
|
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 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));
|
(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 (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()) {
|
if [&tl, &bl, &tr, &br].iter().all(|&e| e.is_none()) {
|
||||||
ctx.push(FrameFragment::new(ctx, center_frame).with_class(base_class));
|
ctx.push(FrameFragment::new(ctx, center_frame).with_class(base_class));
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ascent.set_max(center_frame.ascent());
|
||||||
|
descent.set_max(center_frame.descent());
|
||||||
|
|
||||||
let mut frame = Frame::soft(Size::new(
|
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,
|
ascent + descent,
|
||||||
));
|
));
|
||||||
frame.set_baseline(ascent);
|
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 {
|
if let Some(tl) = tl {
|
||||||
let pos =
|
let pos =
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
@ -49,7 +49,11 @@ $pi_1(Y), a_f(x), a^zeta (x), a^abs(b)_sqrt(c) \
|
|||||||
---
|
---
|
||||||
// Test associativity and scaling.
|
// Test associativity and scaling.
|
||||||
$ 1/(V^2^3^4^5),
|
$ 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,
|
attach(Omega,
|
||||||
tl: attach(2, tl: attach(3, tl: attach(4, tl: 5))),
|
tl: attach(2, tl: attach(3, tl: attach(4, tl: 5))),
|
||||||
tr: attach(2, tr: attach(3, tr: attach(4, tr: 5))),
|
tr: attach(2, tr: attach(3, tr: attach(4, tr: 5))),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user