Centre multirow cells over their rows

This commit is contained in:
gloamxun committed 2026-10-26 20:31:03 +08:00
1 parent e039cfb8a9
commit 8ecbd5e720
5 files changed
+138 -6

No files matched your search

+36
View File
@@ -445,6 +445,42 @@ impl Halign {
+ line_index as i64 * self.line_height;
for (index, cell) in row.cells.iter().enumerate() {
let lines = self.cell_lines(row_index, index);
let row_span = self.cell_row_span(row_index, index);
if row_span > 1 {
if line_index != 0 {
continue;
}
let Some((x, width)) = self.cell_span(row_index, index) else {
continue;
};
let span_rows = (row_index + row_span).min(self.rows.len());
let span_height: i64 = (row_index..span_rows)
.map(|index| self.row_height(index) + self.row_gap(index))
.sum();
let center = y + span_height / 2;
for (offset_index, line) in lines.iter().enumerate() {
let baseline = center - (lines.len() as i64 - 1) * self.line_height / 2
+ self.line_height * 3 / 10
+ offset_index as i64 * self.line_height;
let text_width = crate::text_width(line);
let offset = match cell.alignment {
CellAlignment::Left => 0,
CellAlignment::Center => (width - text_width).max(0) / 2,
CellAlignment::Right => (width - text_width).max(0),
};
list.push(DisplayItem::Text {
font: FontFace::Roman,
x: x + offset,
y: baseline,
size: 10 * 65_536,
text: line.clone(),
});
}
continue;
}
if self.cell_covered(row_index, index) && cell.text.trim().is_empty() {
continue;
}
let Some(line) = lines.get(line_index) else {
continue;
};