diff --git a/library/src/math/row.rs b/library/src/math/row.rs index 6e666e897..1704dbf1e 100644 --- a/library/src/math/row.rs +++ b/library/src/math/row.rs @@ -85,8 +85,16 @@ impl MathRow { self.0.iter() } - pub fn width(&self) -> Abs { - self.iter().map(MathFragment::width).sum() + /// It is very unintuitive, but in current state of things + /// `MathRow` can contain several actual rows. + /// That function deconstructs it to "single" rows. + /// + /// Hopefully that cloner is only a temporary hack + pub fn rows(&self) -> Vec { + self.0 + .split(|frag| matches!(frag, MathFragment::Linebreak)) + .map(|slice| Self(slice.to_vec())) + .collect() } pub fn ascent(&self) -> Abs { @@ -126,23 +134,19 @@ impl MathRow { } pub fn into_aligned_frame( - mut self, + self, ctx: &MathContext, points: &[Abs], align: Align, ) -> Frame { if self.iter().any(|frag| matches!(frag, MathFragment::Linebreak)) { - let fragments: Vec<_> = std::mem::take(&mut self.0); let leading = if ctx.style.size >= MathSize::Text { ParElem::leading_in(ctx.styles()) } else { TIGHT_LEADING.scaled(ctx) }; - let mut rows: Vec<_> = fragments - .split(|frag| matches!(frag, MathFragment::Linebreak)) - .map(|slice| Self(slice.to_vec())) - .collect(); + let mut rows: Vec<_> = self.rows(); if matches!(rows.last(), Some(row) if row.0.is_empty()) { rows.pop(); diff --git a/library/src/math/underover.rs b/library/src/math/underover.rs index 9db799142..df3ba5829 100644 --- a/library/src/math/underover.rs +++ b/library/src/math/underover.rs @@ -203,8 +203,10 @@ fn layout( let gap = gap.scaled(ctx); let body = ctx.layout_row(body)?; let body_class = body.class(); + let body = body.into_fragment(ctx); let glyph = GlyphFragment::new(ctx, c, span); let stretched = glyph.stretch_horizontal(ctx, body.width(), Abs::zero()); + let body = MathRow::new(vec![body]); let mut rows = vec![body, stretched.into()]; ctx.style(if reverse { @@ -243,6 +245,7 @@ pub(super) fn stack( gap: Abs, baseline: usize, ) -> Frame { + let rows: Vec<_> = rows.into_iter().flat_map(|r| r.rows()).collect(); let AlignmentResult { points, width } = alignments(&rows); let rows: Vec<_> = rows .into_iter()