Report TeX outputpenalty for glue breaks

This commit is contained in:
gloamxun committed 2026-10-23 14:22:34 +08:00
1 parent 94559ee431
commit 8007fd1b6c
5 files changed
+31 -8

No files matched your search

+15 -3
View File
@@ -95,8 +95,9 @@ pub struct PageFragment {
pub end: usize,
/// TeX's page cost for the breakpoint: badness plus penalty.
pub cost: i64,
/// Penalty that produced this break: a forced penalty value, the chosen
/// candidate's penalty, or zero for the final page.
/// TeX `\outputpenalty` for this break: the penalty value when the page
/// broke at a penalty, otherwise 10000 (glue break, goal overflow or the
/// final page, exactly as TeX reports it).
pub penalty: i64,
/// Badness of the page height against the page goal.
pub badness: i64,
@@ -656,6 +657,7 @@ impl PageBuilder {
} else {
0
};
let penalty = if penalty == 0 { 10_000 } else { penalty };
PageFragment {
start,
end,
@@ -736,7 +738,17 @@ mod tests {
let pages = builder.build(&nodes);
assert_eq!(pages.len(), 2);
assert_eq!(pages[0].penalty, -10_000);
assert_eq!(pages[1].penalty, 0);
assert_eq!(pages[1].penalty, 10_000);
}
#[test]
fn glue_breaks_report_a_ten_thousand_penalty() {
let builder = PageBuilder::new(100);
let nodes = vec![box_(80, 0), glue(0, 0, 0), box_(80, 0)];
let pages = builder.build(&nodes);
assert_eq!(pages.len(), 2);
assert_eq!(pages[0].penalty, 10_000);
assert_eq!(pages[1].penalty, 10_000);
}
#[test]