Wrap p-column cells and keep wrapped rows splittable

This commit is contained in:
gloamxun committed 2026-10-24 00:57:09 +08:00
1 parent 4153657d0a
commit d1b93ac9be
4 files changed
+346 -63

No files matched your search

+28 -7
View File
@@ -8,7 +8,7 @@
use crate::cmr10::Cmr10Metrics;
use crate::math::{self, MathAtom};
use crate::paragraph::ParagraphFont;
use crate::{Float, FloatPlacement, Halign, HorizontalItem, Page, VerticalItem};
use crate::{CellAlignment, Float, FloatPlacement, Halign, HorizontalItem, Page, VerticalItem};
/// One absolute drawing primitive in scaled points.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -284,19 +284,40 @@ impl Halign {
y += height;
continue;
}
let baseline = y + (self.line_height as f64 * 0.8) as i64;
for (index, cell) in row.cells.iter().enumerate() {
if let Some((x, _)) = self.cell_box(row_index, index) {
let row_height = self.row_height(row_index);
let lines_in_row = (0..row.cells.len())
.map(|index| self.cell_lines(row_index, index).len())
.max()
.unwrap_or(1)
.max(1);
for line_index in 0..lines_in_row {
let baseline = y
+ (self.line_height as f64 * 0.8) as i64
+ line_index as i64 * self.line_height;
for (index, cell) in row.cells.iter().enumerate() {
let lines = self.cell_lines(row_index, index);
let Some(line) = lines.get(line_index) else {
continue;
};
let Some((x, width)) = self.cell_span(row_index, index) else {
continue;
};
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: x + offset,
y: baseline,
size: 10 * 65_536,
text: cell.text.clone(),
text: line.clone(),
});
}
}
y += self.line_height;
y += row_height;
}
list
}