Expose prevgraf to the output routine
This commit is contained in:
1 parent
d63db8d12d
commit
7a42ddc1bf
4 files changed
+68
-6
No files matched your search
@@ -42,6 +42,8 @@ pub struct OutputContext {
|
||||
pub pageno: i64,
|
||||
/// TeX `\deadcycles`: output routines since the last shipout.
|
||||
pub deadcycles: i64,
|
||||
/// TeX `\prevgraf`: lines in the paragraph most recently broken.
|
||||
pub prev_graf: 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.
|
||||
@@ -67,6 +69,7 @@ impl Default for OutputContext {
|
||||
output_penalty: 0,
|
||||
pageno: 0,
|
||||
deadcycles: 0,
|
||||
prev_graf: 0,
|
||||
// TeX's default insertion multiplier is 1000.
|
||||
insertion_counts: [1000; 256],
|
||||
insertion_dimens: [0; 256],
|
||||
@@ -223,6 +226,7 @@ enum IntegerRegister {
|
||||
PageNo,
|
||||
DeadCycles,
|
||||
OutputPenalty,
|
||||
PrevGraf,
|
||||
InsertionCount(u8),
|
||||
}
|
||||
|
||||
@@ -234,6 +238,7 @@ impl Integer {
|
||||
IntegerRegister::PageNo => context.pageno,
|
||||
IntegerRegister::DeadCycles => context.deadcycles,
|
||||
IntegerRegister::OutputPenalty => context.output_penalty,
|
||||
IntegerRegister::PrevGraf => context.prev_graf,
|
||||
IntegerRegister::InsertionCount(class) => context.insertion_counts[class as usize],
|
||||
},
|
||||
}
|
||||
@@ -581,6 +586,7 @@ fn parse_integer(tokens: &[Token], index: &mut usize) -> Result<Integer, String>
|
||||
"pageno" => IntegerRegister::PageNo,
|
||||
"deadcycles" => IntegerRegister::DeadCycles,
|
||||
"outputpenalty" => IntegerRegister::OutputPenalty,
|
||||
"prevgraf" => IntegerRegister::PrevGraf,
|
||||
"count" => {
|
||||
*index += 1;
|
||||
if matches!(
|
||||
@@ -741,6 +747,7 @@ fn execute(ops: &[Op], context: &mut OutputContext, shipped: &mut usize) -> Resu
|
||||
IntegerRegister::PageNo => context.pageno = value,
|
||||
IntegerRegister::DeadCycles => context.deadcycles = value,
|
||||
IntegerRegister::OutputPenalty => context.output_penalty = value,
|
||||
IntegerRegister::PrevGraf => context.prev_graf = value,
|
||||
IntegerRegister::InsertionCount(class) => {
|
||||
context.insertion_counts[*class as usize] = value;
|
||||
}
|
||||
@@ -786,6 +793,7 @@ mod tests {
|
||||
output_penalty: 0,
|
||||
pageno: 1,
|
||||
deadcycles: 0,
|
||||
prev_graf: 0,
|
||||
..OutputContext::default()
|
||||
}
|
||||
}
|
||||
@@ -852,6 +860,21 @@ mod tests {
|
||||
assert!(!plain.assigns_vsize());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_routine_sees_prevgraf() {
|
||||
let mut context = context(0);
|
||||
context.prev_graf = 4;
|
||||
let program = OutputProgram::parse(r"\ifnum\prevgraf=4\pageno=9\fi").unwrap();
|
||||
assert_eq!(program.shipout_count(&mut context).unwrap(), 0);
|
||||
assert_eq!(context.pageno, 9);
|
||||
|
||||
let copy = OutputProgram::parse(r"\pageno=\prevgraf").unwrap();
|
||||
let mut context = self::context(0);
|
||||
context.prev_graf = 6;
|
||||
copy.shipout_count(&mut context).unwrap();
|
||||
assert_eq!(context.pageno, 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_routine_can_assign_registers() {
|
||||
let mut context = context(0);
|
||||
|
||||
Reference in new issue
Block a user