Continue long alignments across pages
This commit is contained in:
1 parent
f980ed7f56
commit
4153657d0a
3 files changed
+69
-4
No files matched your search
@@ -976,6 +976,33 @@ fn document_nodes(
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if let VerticalItem::Halign(halign) = item {
|
||||
let capacity = (document.page_goal - document.top_skip)
|
||||
.max(halign.line_height)
|
||||
.max(1);
|
||||
let chunks = halign.split_for_height(capacity);
|
||||
if chunks.len() > 1 {
|
||||
// TeX breaks a long alignment at row boundaries; each
|
||||
// chunk becomes its own vertical node with a zero glue
|
||||
// between them so the page builder can break there.
|
||||
let last = chunks.len() - 1;
|
||||
for (chunk_index, chunk) in chunks.into_iter().enumerate() {
|
||||
nodes.push(VerticalNode::Box {
|
||||
height: chunk.height,
|
||||
depth: 0,
|
||||
});
|
||||
owners.push(index);
|
||||
items.push(VerticalItem::Halign(chunk));
|
||||
if chunk_index < last {
|
||||
nodes.push(VerticalNode::Glue(VerticalGlue::new(0, 0, 0)));
|
||||
owners.push(index);
|
||||
items.push(VerticalItem::Glue(0));
|
||||
}
|
||||
}
|
||||
previous_paragraph = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let node = match item {
|
||||
VerticalItem::Box(vertical_box) => VerticalNode::Box {
|
||||
height: vertical_box.height,
|
||||
@@ -6142,6 +6169,44 @@ mod tests {
|
||||
assert_eq!(layout.pages()[0].items.len(), 1);
|
||||
assert_eq!(layout.pages()[1].items.len(), 1);
|
||||
}
|
||||
#[test]
|
||||
fn paged_layout_splits_a_tall_halign_across_pages() {
|
||||
let mut rows = Vec::new();
|
||||
for n in 0..30_u64 {
|
||||
rows.push(HalignRow {
|
||||
cells: vec![
|
||||
HalignCell {
|
||||
text: format!("r{n}"),
|
||||
span: 1,
|
||||
alignment: CellAlignment::Left,
|
||||
},
|
||||
HalignCell {
|
||||
text: "value".to_owned(),
|
||||
span: 1,
|
||||
alignment: CellAlignment::Left,
|
||||
},
|
||||
],
|
||||
rule: false,
|
||||
});
|
||||
}
|
||||
let document = Document::new(300 * 65_536, vec![Unit::halign(0, rows, 2, 0)]);
|
||||
let engine = Engine::layout_paged(&document).expect("paged");
|
||||
assert!(engine.pages().len() > 1, "pages: {}", engine.pages().len());
|
||||
let mut rows_seen = 0;
|
||||
let mut widths = Vec::new();
|
||||
for page in engine.pages() {
|
||||
for item in &page.items {
|
||||
if let VerticalItem::Halign(halign) = item {
|
||||
rows_seen += halign.rows.len();
|
||||
widths.push(halign.column_widths.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_eq!(rows_seen, 30);
|
||||
assert!(!widths.is_empty());
|
||||
assert!(widths.windows(2).all(|pair| pair[0] == pair[1]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checkpoint_round_trips_through_serde() {
|
||||
let engine = Engine::layout(&document());
|
||||
|
||||
Reference in new issue
Block a user