Report page badness and held-over insertions to the output routine

This commit is contained in:
gloamxun committed 2026-10-24 00:02:46 +08:00
1 parent bf31936146
commit 01ed1b7c21
5 files changed
+89 -6

No files matched your search

+16
View File
@@ -30,6 +30,8 @@ pub struct OutputContext {
pub page_filll_stretch: i64,
/// TeX `\pageshrink`: shrink of the vertical glue so far.
pub page_shrink: i64,
/// TeX `\vbadness`: badness of the break that produced the page.
pub vbadness: i64,
/// TeX `\vsize`: the configured page height.
pub vsize: i64,
/// TeX `\topskip`.
@@ -47,6 +49,8 @@ pub struct OutputContext {
pub max_deadcycles: i64,
/// TeX `\prevgraf`: lines in the paragraph most recently broken.
pub prev_graf: i64,
/// TeX `\insertpenalties`: insertion items held over from the page.
pub insert_penalties: i64,
/// TeX `\count<n>` for insertion class `n`: the insertion multiplier.
pub insertion_counts: [i64; 256],
/// TeX `\dimen<n>` for insertion class `n`: the class' maximum size.
@@ -66,6 +70,7 @@ impl Default for OutputContext {
page_fill_stretch: 0,
page_filll_stretch: 0,
page_shrink: 0,
vbadness: 0,
vsize: 0,
top_skip: 0,
max_depth: 0,
@@ -74,6 +79,7 @@ impl Default for OutputContext {
deadcycles: 0,
max_deadcycles: 25,
prev_graf: 0,
insert_penalties: 0,
// TeX's default insertion multiplier is 1000.
insertion_counts: [1000; 256],
insertion_dimens: [0; 256],
@@ -298,6 +304,8 @@ enum IntegerRegister {
PageNo,
DeadCycles,
MaxDeadCycles,
VBadness,
InsertPenalties,
OutputPenalty,
PrevGraf,
InsertionCount(u8),
@@ -313,6 +321,8 @@ impl Integer {
IntegerRegister::MaxDeadCycles => context.max_deadcycles,
IntegerRegister::OutputPenalty => context.output_penalty,
IntegerRegister::PrevGraf => context.prev_graf,
IntegerRegister::VBadness => context.vbadness,
IntegerRegister::InsertPenalties => context.insert_penalties,
IntegerRegister::InsertionCount(class) => context.insertion_counts[class as usize],
},
}
@@ -726,6 +736,8 @@ fn parse_integer(tokens: &[Token], index: &mut usize) -> Result<Integer, String>
"maxdeadcycles" => IntegerRegister::MaxDeadCycles,
"outputpenalty" => IntegerRegister::OutputPenalty,
"prevgraf" => IntegerRegister::PrevGraf,
"vbadness" => IntegerRegister::VBadness,
"insertpenalties" => IntegerRegister::InsertPenalties,
"count" => {
*index += 1;
if matches!(
@@ -949,6 +961,8 @@ fn read_integer(context: &OutputContext, register: IntegerRegister) -> i64 {
IntegerRegister::MaxDeadCycles => context.max_deadcycles,
IntegerRegister::OutputPenalty => context.output_penalty,
IntegerRegister::PrevGraf => context.prev_graf,
IntegerRegister::VBadness => context.vbadness,
IntegerRegister::InsertPenalties => context.insert_penalties,
IntegerRegister::InsertionCount(class) => context.insertion_counts[class as usize],
}
}
@@ -963,6 +977,8 @@ fn write_integer(context: &mut OutputContext, register: IntegerRegister, value:
IntegerRegister::InsertionCount(class) => {
context.insertion_counts[class as usize] = value;
}
// Read-only for the output routine: the parser never assigns them.
IntegerRegister::VBadness | IntegerRegister::InsertPenalties => {}
}
}