mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Make under/overlines behave the same as accents in attach base (#4695)
This commit is contained in:
parent
a88899ed75
commit
a6a8cdaa28
@ -67,7 +67,7 @@ fn layout_underoverline(
|
||||
span: Span,
|
||||
position: Position,
|
||||
) -> SourceResult<()> {
|
||||
let (extra_height, content, line_pos, content_pos, baseline, bar_height);
|
||||
let (extra_height, content, line_pos, content_pos, baseline, bar_height, line_adjust);
|
||||
match position {
|
||||
Position::Under => {
|
||||
let sep = scaled!(ctx, styles, underbar_extra_descender);
|
||||
@ -79,7 +79,8 @@ fn layout_underoverline(
|
||||
|
||||
line_pos = Point::with_y(content.height() + gap + bar_height / 2.0);
|
||||
content_pos = Point::zero();
|
||||
baseline = content.ascent()
|
||||
baseline = content.ascent();
|
||||
line_adjust = -content.italics_correction();
|
||||
}
|
||||
Position::Over => {
|
||||
let sep = scaled!(ctx, styles, overbar_extra_ascender);
|
||||
@ -93,21 +94,25 @@ fn layout_underoverline(
|
||||
line_pos = Point::with_y(sep + bar_height / 2.0);
|
||||
content_pos = Point::with_y(extra_height);
|
||||
baseline = content.ascent() + extra_height;
|
||||
line_adjust = Abs::zero();
|
||||
}
|
||||
}
|
||||
|
||||
let width = content.width();
|
||||
let height = content.height() + extra_height;
|
||||
let size = Size::new(width, height);
|
||||
let line_width = width + line_adjust;
|
||||
|
||||
let content_class = content.class();
|
||||
let content_is_text_like = content.is_text_like();
|
||||
let content_italics_correction = content.italics_correction();
|
||||
let mut frame = Frame::soft(size);
|
||||
frame.set_baseline(baseline);
|
||||
frame.push_frame(content_pos, content.into_frame());
|
||||
frame.push(
|
||||
line_pos,
|
||||
FrameItem::Shape(
|
||||
Geometry::Line(Point::with_x(width)).stroked(FixedStroke {
|
||||
Geometry::Line(Point::with_x(line_width)).stroked(FixedStroke {
|
||||
paint: TextElem::fill_in(styles).as_decoration(),
|
||||
thickness: bar_height,
|
||||
..FixedStroke::default()
|
||||
@ -116,7 +121,12 @@ fn layout_underoverline(
|
||||
),
|
||||
);
|
||||
|
||||
ctx.push(FrameFragment::new(ctx, styles, frame).with_class(content_class));
|
||||
ctx.push(
|
||||
FrameFragment::new(ctx, styles, frame)
|
||||
.with_class(content_class)
|
||||
.with_text_like(content_is_text_like)
|
||||
.with_italics_correction(content_italics_correction),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
BIN
tests/ref/math-underover-line-subscript.png
Normal file
BIN
tests/ref/math-underover-line-subscript.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
tests/ref/math-underover-line-superscript.png
Normal file
BIN
tests/ref/math-underover-line-superscript.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
@ -33,3 +33,15 @@ $ undershell(
|
||||
1 + overshell(2 + ..., x + y),
|
||||
"all stuff"
|
||||
) $
|
||||
|
||||
--- math-underover-line-subscript ---
|
||||
// Test effect of lines on subscripts.
|
||||
$A_2 != overline(A)_2 != underline(A)_2 != underline(overline(A))_2 \
|
||||
V_y != overline(V)_y != underline(V)_y != underline(overline(V))_y \
|
||||
W_l != overline(W)_l != underline(W)_l != underline(overline(W))_l$
|
||||
|
||||
--- math-underover-line-superscript ---
|
||||
// Test effect of lines on superscripts.
|
||||
$J^b != overline(J)^b != underline(J)^b != underline(overline(J))^b \
|
||||
K^3 != overline(K)^3 != underline(K)^3 != underline(overline(K))^3 \
|
||||
T^i != overline(T)^i != underline(T)^i != underline(overline(T))^i$
|
||||
|
Loading…
x
Reference in New Issue
Block a user