mirror of
https://github.com/typst/typst
synced 2025-05-16 01:55:28 +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()
|
self.0.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn width(&self) -> Abs {
|
/// It is very unintuitive, but in current state of things
|
||||||
self.iter().map(MathFragment::width).sum()
|
/// `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 {
|
pub fn ascent(&self) -> Abs {
|
||||||
@ -126,23 +134,19 @@ impl MathRow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_aligned_frame(
|
pub fn into_aligned_frame(
|
||||||
mut self,
|
self,
|
||||||
ctx: &MathContext,
|
ctx: &MathContext,
|
||||||
points: &[Abs],
|
points: &[Abs],
|
||||||
align: Align,
|
align: Align,
|
||||||
) -> Frame {
|
) -> Frame {
|
||||||
if self.iter().any(|frag| matches!(frag, MathFragment::Linebreak)) {
|
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 {
|
let leading = if ctx.style.size >= MathSize::Text {
|
||||||
ParElem::leading_in(ctx.styles())
|
ParElem::leading_in(ctx.styles())
|
||||||
} else {
|
} else {
|
||||||
TIGHT_LEADING.scaled(ctx)
|
TIGHT_LEADING.scaled(ctx)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut rows: Vec<_> = fragments
|
let mut rows: Vec<_> = self.rows();
|
||||||
.split(|frag| matches!(frag, MathFragment::Linebreak))
|
|
||||||
.map(|slice| Self(slice.to_vec()))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if matches!(rows.last(), Some(row) if row.0.is_empty()) {
|
if matches!(rows.last(), Some(row) if row.0.is_empty()) {
|
||||||
rows.pop();
|
rows.pop();
|
||||||
|
@ -203,8 +203,10 @@ fn layout(
|
|||||||
let gap = gap.scaled(ctx);
|
let gap = gap.scaled(ctx);
|
||||||
let body = ctx.layout_row(body)?;
|
let body = ctx.layout_row(body)?;
|
||||||
let body_class = body.class();
|
let body_class = body.class();
|
||||||
|
let body = body.into_fragment(ctx);
|
||||||
let glyph = GlyphFragment::new(ctx, c, span);
|
let glyph = GlyphFragment::new(ctx, c, span);
|
||||||
let stretched = glyph.stretch_horizontal(ctx, body.width(), Abs::zero());
|
let stretched = glyph.stretch_horizontal(ctx, body.width(), Abs::zero());
|
||||||
|
let body = MathRow::new(vec![body]);
|
||||||
|
|
||||||
let mut rows = vec![body, stretched.into()];
|
let mut rows = vec![body, stretched.into()];
|
||||||
ctx.style(if reverse {
|
ctx.style(if reverse {
|
||||||
@ -243,6 +245,7 @@ pub(super) fn stack(
|
|||||||
gap: Abs,
|
gap: Abs,
|
||||||
baseline: usize,
|
baseline: usize,
|
||||||
) -> Frame {
|
) -> Frame {
|
||||||
|
let rows: Vec<_> = rows.into_iter().flat_map(|r| r.rows()).collect();
|
||||||
let AlignmentResult { points, width } = alignments(&rows);
|
let AlignmentResult { points, width } = alignments(&rows);
|
||||||
let rows: Vec<_> = rows
|
let rows: Vec<_> = rows
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user