mirror of
https://github.com/typst/typst
synced 2025-05-15 17:45:27 +08:00
Some backslash in math fixes (#1561)
This commit is contained in:
parent
1928154e69
commit
529bac11b6
@ -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();
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user