summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsitandr <60141933+sitandr@users.noreply.github.com>2023-06-24 15:32:03 +0300
committerGitHub <noreply@github.com>2023-06-24 14:32:03 +0200
commit529bac11b64d658460ae53364559e5fa6eb4fb67 (patch)
treeb14de4fb73574b3d6a187481eb454e2b25624189
parent1928154e695a0e4655d1574e171e54e0d00b3f6a (diff)
Some backslash in math fixes (#1561)
-rw-r--r--library/src/math/row.rs20
-rw-r--r--library/src/math/underover.rs3
2 files changed, 15 insertions, 8 deletions
diff --git a/library/src/math/row.rs b/library/src/math/row.rs
index 6e666e89..1704dbf1 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> {
+ 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 9db79914..df3ba582 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()