mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Fix math alignment points
This commit is contained in:
parent
60dfe8f893
commit
17f8939f86
@ -86,7 +86,7 @@ impl MathRow {
|
|||||||
let points = alignments(&rows);
|
let points = alignments(&rows);
|
||||||
for (i, row) in rows.into_iter().enumerate() {
|
for (i, row) in rows.into_iter().enumerate() {
|
||||||
let size = frame.size_mut();
|
let size = frame.size_mut();
|
||||||
let sub = row.to_line_frame(ctx, &points);
|
let sub = row.to_line_frame(ctx, &points, Align::Center);
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
size.y += leading;
|
size.y += leading;
|
||||||
}
|
}
|
||||||
@ -97,11 +97,11 @@ impl MathRow {
|
|||||||
}
|
}
|
||||||
frame
|
frame
|
||||||
} else {
|
} else {
|
||||||
self.to_line_frame(ctx, &[])
|
self.to_line_frame(ctx, &[], Align::Center)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_line_frame(self, ctx: &MathContext, points: &[Abs]) -> Frame {
|
pub fn to_line_frame(self, ctx: &MathContext, points: &[Abs], align: Align) -> Frame {
|
||||||
let ascent = self.0.iter().map(MathFragment::ascent).max().unwrap_or_default();
|
let ascent = self.0.iter().map(MathFragment::ascent).max().unwrap_or_default();
|
||||||
let descent = self.0.iter().map(MathFragment::descent).max().unwrap_or_default();
|
let descent = self.0.iter().map(MathFragment::descent).max().unwrap_or_default();
|
||||||
|
|
||||||
@ -110,6 +110,16 @@ impl MathRow {
|
|||||||
let mut x = Abs::zero();
|
let mut x = Abs::zero();
|
||||||
frame.set_baseline(ascent);
|
frame.set_baseline(ascent);
|
||||||
|
|
||||||
|
if let (Some(&first), Align::Center) = (points.first(), align) {
|
||||||
|
let segment: Abs = self
|
||||||
|
.0
|
||||||
|
.iter()
|
||||||
|
.take_while(|fragment| !matches!(fragment, MathFragment::Align))
|
||||||
|
.map(|fragment| fragment.width())
|
||||||
|
.sum();
|
||||||
|
x = first - segment;
|
||||||
|
}
|
||||||
|
|
||||||
let mut fragments = self.0.into_iter().peekable();
|
let mut fragments = self.0.into_iter().peekable();
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while let Some(fragment) = fragments.next() {
|
while let Some(fragment) = fragments.next() {
|
||||||
|
@ -290,8 +290,10 @@ pub(super) fn stack(
|
|||||||
let mut height = rows.len().saturating_sub(1) as f64 * gap;
|
let mut height = rows.len().saturating_sub(1) as f64 * gap;
|
||||||
|
|
||||||
let points = alignments(&rows);
|
let points = alignments(&rows);
|
||||||
let rows: Vec<_> =
|
let rows: Vec<_> = rows
|
||||||
rows.into_iter().map(|row| row.to_line_frame(ctx, &points)).collect();
|
.into_iter()
|
||||||
|
.map(|row| row.to_line_frame(ctx, &points, align))
|
||||||
|
.collect();
|
||||||
|
|
||||||
for row in &rows {
|
for row in &rows {
|
||||||
height += row.height();
|
height += row.height();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user