Lay out align and gather displays row by row

This commit is contained in:
gloamxun committed 2026-10-24 12:39:02 +08:00
1 parent 8c42f2de2f
commit cce656a407
7 files changed
+529 -19

No files matched your search

+38
View File
@@ -728,6 +728,44 @@ impl Page {
cursor += width;
}
}
MathAtom::Aligned { rows, centered } => {
let layout = math::layout_aligned(rows, *centered, font);
let x0 = x + (layout.total_width - layout.body_width) / 2;
let first_baseline = baseline - layout.height + layout.first_height;
for (index, row) in rows.iter().enumerate() {
let row_baseline = first_baseline + layout.baselines[index];
for (cell_index, cell) in row.cells.iter().enumerate() {
let cell_box = layout.boxes[index][cell_index];
let cell_x = if *centered {
x0 + (layout.body_width - cell_box.width) / 2
} else {
let start = layout.column_starts[cell_index];
let width = layout.column_widths[cell_index];
if cell_index % 2 == 0 {
x0 + start + width - cell_box.width
} else {
x0 + start
}
};
Self::paint_math(cell, font, cell_x, row_baseline, size, list);
}
if let Some(tag) = &row.tag {
let tag_width = layout.tag_widths[index];
let mut pen = x + layout.total_width - tag_width;
for character in tag.chars() {
let width = Cmr10Metrics::Roman.width(character);
list.push(DisplayItem::Text {
font: FontFace::Roman,
x: pen,
y: row_baseline,
size,
text: character.to_string(),
});
pen += width;
}
}
}
}
MathAtom::Tagged { body, tag } => {
let body_box = math::layout_math(body, font);
Self::paint_math(body, font, x, baseline, size, list);