Expose page stretch and shrink to the output routine

This commit is contained in:
gloamxun committed 2026-10-23 03:23:57 +08:00
1 parent 62d3c4154e
commit ca36c94eb3
5 files changed
+69 -6

No files matched your search

+25
View File
@@ -79,6 +79,10 @@ pub struct PageFragment {
pub height: i64,
/// Depth of the page box, capped at `max_depth`.
pub depth: i64,
/// Total stretch of the vertical glue on the page.
pub stretch: i64,
/// Total shrink of the vertical glue on the page.
pub shrink: i64,
/// Accepted insertion space per class, including material held over from
/// the previous page.
pub insertions: Vec<InsertionSpace>,
@@ -90,6 +94,7 @@ struct Candidate {
badness: i64,
height: i64,
depth: i64,
stretch: i64,
shrink: i64,
reserved: i64,
penalty: i64,
@@ -201,6 +206,8 @@ impl PageBuilder {
end,
height,
depth,
stretch,
shrink,
badness,
badness + *penalty,
*penalty,
@@ -242,6 +249,8 @@ impl PageBuilder {
best.end,
best.height,
best.depth,
best.stretch,
best.shrink,
best.badness,
best.cost,
best.penalty,
@@ -321,6 +330,7 @@ impl PageBuilder {
badness,
height,
depth,
stretch,
shrink,
reserved,
end,
@@ -357,6 +367,8 @@ impl PageBuilder {
end: usize,
height: i64,
depth: i64,
stretch: i64,
shrink: i64,
badness: i64,
cost: i64,
penalty: i64,
@@ -370,6 +382,8 @@ impl PageBuilder {
badness,
height,
depth,
stretch,
shrink,
insertions,
}
}
@@ -447,6 +461,17 @@ mod tests {
assert_eq!(pages[0].badness, 0);
}
#[test]
fn fragments_report_glue_stretch_and_shrink() {
let builder = PageBuilder::new(100);
let nodes = vec![box_(40, 0), glue(0, 20, 5), box_(40, 0)];
let pages = builder.build(&nodes);
assert_eq!(pages.len(), 1);
assert_eq!(pages[0].height, 80);
assert_eq!(pages[0].stretch, 20);
assert_eq!(pages[0].shrink, 5);
}
#[test]
fn forced_penalty_breaks_the_page() {
let builder = PageBuilder::new(100);