From a6a8cdaa28abe22c3a40e7a96d15e5e02e8a445e Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 9 Aug 2024 07:40:29 +0000 Subject: [PATCH] Make under/overlines behave the same as accents in attach base (#4695) --- crates/typst/src/math/underover.rs | 18 ++++++++++++++---- tests/ref/math-underover-line-subscript.png | Bin 0 -> 1541 bytes tests/ref/math-underover-line-superscript.png | Bin 0 -> 1453 bytes tests/suite/math/underover.typ | 12 ++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 tests/ref/math-underover-line-subscript.png create mode 100644 tests/ref/math-underover-line-superscript.png diff --git a/crates/typst/src/math/underover.rs b/crates/typst/src/math/underover.rs index 68a399835..f1789b7ad 100644 --- a/crates/typst/src/math/underover.rs +++ b/crates/typst/src/math/underover.rs @@ -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(()) } diff --git a/tests/ref/math-underover-line-subscript.png b/tests/ref/math-underover-line-subscript.png new file mode 100644 index 0000000000000000000000000000000000000000..9a4b886b8ea713e8e85800abaef970d03f8eee0c GIT binary patch literal 1541 zcmV+g2KxDlP)u;1*9>8(`f!)N7Zd_x?`i^zk7n{{=*43yHVvJN!gBKLg#%n=QyrF@XQaE)4no8+~ zOAFEhrPxxW(w4R~Ftx?fk+v|U?XoA`~~ln5unz>rn4VVun>4gI>X<+xOfaka-Ki}7#|5iWpo)lcj}pdZjp_C@@b z(Qw;;0o~;al+b@J0lIWhveyB+-J>W&^DrLHz5~!@dQr+AISsliM^VP!SPtkmfs%j6 ztl@C^_+LZlLg^?I$KL%Mbfy`Ug3gCPXDdN5U%qF+XxLTCKgUqaLOj1#WFzekZ8M=v z39)sN5PblgZ=aYC%3&cM$q*F)1on~CVl63uzM=GBC^JLBlib z@os1Urc9=VCX-2ST;zgzp23s7t7Ocya;?d99ANMZNXsS1ztj~s-1I~fT`SkmI9ZHz zq#J4S%?-zZG-F3KgDZ1Q0DRSf zrb-*M7OelkZa8c&%>Yb0956NEi#~TbCc!xoG8`U#c(sR~|FuOw zGi>v>hp1j`BWyDOZGZj}vR)kn#gzj<<;@r1wRDf+Fk3%`%2C2b_8_e|3H!Z-ooz(A z+Xe;b_6{NaC4|2ajE4`ufxR5vP6yJ)opd&%OAjF}J59|Xx->NZ`i|loa|t&;%5D_j zCqgU~q7$I#ozNbXF(FbH3n6#=VE5Ev6sr&^t3>83K+-u|J#z_<%s<-&ird{*>~;qM z8kZh*qMsl7#_a|mZ~fi?O3>}j98u?Q9VlQoWqd7S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b/tests/suite/math/underover.typ @@ -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$