Report paragraph depth to the page builder

This commit is contained in:
gloamxun committed 2026-10-23 23:31:47 +08:00
1 parent bd28917f05
commit 0f4c1f85ae
8 files changed
+140 -9

No files matched your search

+54 -2
View File
@@ -910,6 +910,13 @@ fn document_nodes(
}
if let VerticalItem::Paragraph(paragraph) = item {
if paragraph.lines.len() > 1 {
// Paragraphs built with fixed-cell styles mix raw units with
// TFM extents; only trust a descent that fits the box.
let depth = if paragraph.height > paragraph.depth {
paragraph.depth
} else {
0
};
// TeX breaks pages between lines. Expand a paragraph into
// one node per line so the page builder is free to break
// inside it; each slice renders as its own single-line
@@ -921,9 +928,17 @@ fn document_nodes(
} else {
None
};
let remaining_depth = if remaining.height > remaining.depth {
remaining.depth
} else {
0
};
// The line grid already budgets the descent; keep the
// grid height and report the descent separately for
// `\pagedepth`/`\maxdepth`.
nodes.push(VerticalNode::Box {
height: remaining.height,
depth: 0,
depth: remaining_depth,
});
owners.push(index);
items.push(VerticalItem::Paragraph(remaining.clone()));
@@ -958,7 +973,11 @@ fn document_nodes(
},
VerticalItem::Paragraph(paragraph) => VerticalNode::Box {
height: paragraph.height,
depth: 0,
depth: if paragraph.height > paragraph.depth {
paragraph.depth
} else {
0
},
},
VerticalItem::Halign(halign) => VerticalNode::Box {
height: halign.height,
@@ -5066,6 +5085,7 @@ mod tests {
lines,
height: 100,
width: 50,
depth: 0,
font: ParagraphFont::Roman,
left_skip: 0,
line_indents: vec![0; 10],
@@ -6191,6 +6211,38 @@ mod tests {
);
}
#[test]
fn output_routine_sees_paragraph_depth() {
let paragraph = Paragraph {
lines: vec![Vec::new()],
height: 8 * 65_536,
width: 5 * 65_536,
depth: 2 * 65_536,
font: ParagraphFont::Roman,
left_skip: 0,
line_indents: vec![0],
line_baselines: vec![8 * 65_536],
centered: false,
right_aligned: false,
};
let mut document = Document::new(
300 * 65_536,
vec![Unit::vertical(1, vec![VerticalItem::Paragraph(paragraph)])],
);
document.max_depth = 5 * 65_536;
document.output_routine = Some("\\ifdim\\pagedepth>0pt\\shipout\\box255\\fi".to_string());
let deep = Engine::layout_paged(&document).expect("paragraph page");
assert_eq!(deep.pages().len(), 1, "maxdepth keeps the paragraph depth");
document.max_depth = 0;
let capped = Engine::layout_paged(&document).expect("paragraph page");
assert_eq!(capped.pages().len(), 0, "maxdepth zero drops the depth");
document.output_routine = Some("\\ifdim\\pagedepth=0pt\\shipout\\box255\\fi".to_string());
let zero = Engine::layout_paged(&document).expect("paragraph page");
assert_eq!(zero.pages().len(), 1);
}
#[test]
fn page_prev_graf_counts_the_last_paragraph_lines() {
let style = ParagraphStyle {