Expose page depth to the output routine

This commit is contained in:
gloamxun committed 2026-10-23 03:21:36 +08:00
1 parent c8805af755
commit 62d3c4154e
4 files changed
+52 -7

No files matched your search

+28
View File
@@ -1650,6 +1650,7 @@ impl Engine {
};
let mut pages = Vec::new();
let mut page_penalties = Vec::new();
let mut page_depths = Vec::new();
let mut held: BTreeMap<u8, Vec<VerticalItem>> = BTreeMap::new();
for fragment in builder.build(&nodes) {
let mut items = Vec::new();
@@ -1707,6 +1708,7 @@ impl Engine {
page.seal_in_place();
pages.push(page);
page_penalties.push(fragment.penalty);
page_depths.push(fragment.depth);
}
// Insertion material that did not fit its class limit on the page where
@@ -1730,6 +1732,7 @@ impl Engine {
page.seal_in_place();
pages.push(page);
page_penalties.push(0);
page_depths.push(0);
}
if let Some(source) = &document.output_routine {
let program = output::OutputProgram::parse(source).ok()?;
@@ -1739,6 +1742,7 @@ impl Engine {
let context = output::OutputContext {
page_goal: document.page_goal,
page_total,
page_depth: page_depths.get(index).copied().unwrap_or(0),
vsize: document.page_goal,
top_skip: document.top_skip,
max_depth: document.max_depth,
@@ -5040,6 +5044,30 @@ mod tests {
);
}
#[test]
fn output_routine_sees_the_page_depth() {
let math = Unit {
id: 1,
source: String::new(),
items: vec![VerticalItem::Math {
atom: crate::math::MathAtom::Symbol('x'),
width: 10,
height: 500_000,
depth: 300_000,
}],
paragraph_style: None,
};
let mut document = Document::new(800_000, vec![math]);
document.max_depth = 400_000;
document.output_routine = Some(r"\ifdim\pagedepth>4pt\shipout\box255\fi".to_owned());
let kept = Engine::layout_paged(&document).expect("math is page-buildable");
assert_eq!(kept.pages().len(), 1);
document.max_depth = 0;
let dropped = Engine::layout_paged(&document).expect("math is page-buildable");
assert_eq!(dropped.pages().len(), 0);
}
#[test]
fn paged_layout_refuses_floats_but_places_insertions() {
let floated = Document::new(100, vec![Unit::float(1, FloatPlacement::Top, 100, 20)]);