Ship the page after maxdeadcycles
This commit is contained in:
1 parent
8007fd1b6c
commit
4111080422
4 files changed
+84
-8
No files matched your search
@@ -42,6 +42,9 @@ pub struct OutputContext {
|
||||
pub pageno: i64,
|
||||
/// TeX `\deadcycles`: output routines since the last shipout.
|
||||
pub deadcycles: i64,
|
||||
/// TeX `\maxdeadcycles`: dead cycles allowed before TeX ships the
|
||||
/// page itself.
|
||||
pub max_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.
|
||||
@@ -69,6 +72,7 @@ impl Default for OutputContext {
|
||||
output_penalty: 0,
|
||||
pageno: 0,
|
||||
deadcycles: 0,
|
||||
max_deadcycles: 25,
|
||||
prev_graf: 0,
|
||||
// TeX's default insertion multiplier is 1000.
|
||||
insertion_counts: [1000; 256],
|
||||
@@ -231,6 +235,7 @@ enum Integer {
|
||||
enum IntegerRegister {
|
||||
PageNo,
|
||||
DeadCycles,
|
||||
MaxDeadCycles,
|
||||
OutputPenalty,
|
||||
PrevGraf,
|
||||
InsertionCount(u8),
|
||||
@@ -243,6 +248,7 @@ impl Integer {
|
||||
Self::Register(register) => match register {
|
||||
IntegerRegister::PageNo => context.pageno,
|
||||
IntegerRegister::DeadCycles => context.deadcycles,
|
||||
IntegerRegister::MaxDeadCycles => context.max_deadcycles,
|
||||
IntegerRegister::OutputPenalty => context.output_penalty,
|
||||
IntegerRegister::PrevGraf => context.prev_graf,
|
||||
IntegerRegister::InsertionCount(class) => context.insertion_counts[class as usize],
|
||||
@@ -420,12 +426,13 @@ fn parse_sequence(tokens: &[Token], index: &mut usize, stop: &[&str]) -> Result<
|
||||
}
|
||||
ops.push(Op::Message(text));
|
||||
}
|
||||
"pageno" | "deadcycles" | "outputpenalty" | "count" | "dimen" | "skip"
|
||||
| "vsize" => {
|
||||
"pageno" | "deadcycles" | "maxdeadcycles" | "outputpenalty" | "count" | "dimen"
|
||||
| "skip" | "vsize" => {
|
||||
*index += 1;
|
||||
let (integer_register, dimension_register) = match name.as_str() {
|
||||
"pageno" => (Some(IntegerRegister::PageNo), None),
|
||||
"deadcycles" => (Some(IntegerRegister::DeadCycles), None),
|
||||
"maxdeadcycles" => (Some(IntegerRegister::MaxDeadCycles), None),
|
||||
"outputpenalty" => (Some(IntegerRegister::OutputPenalty), None),
|
||||
"count" => {
|
||||
let class = parse_insertion_class(tokens, index, "\\count", false)?;
|
||||
@@ -591,6 +598,7 @@ fn parse_integer(tokens: &[Token], index: &mut usize) -> Result<Integer, String>
|
||||
let register = match name.as_str() {
|
||||
"pageno" => IntegerRegister::PageNo,
|
||||
"deadcycles" => IntegerRegister::DeadCycles,
|
||||
"maxdeadcycles" => IntegerRegister::MaxDeadCycles,
|
||||
"outputpenalty" => IntegerRegister::OutputPenalty,
|
||||
"prevgraf" => IntegerRegister::PrevGraf,
|
||||
"count" => {
|
||||
@@ -773,6 +781,7 @@ fn execute(ops: &[Op], context: &mut OutputContext, shipped: &mut usize) -> Resu
|
||||
match register {
|
||||
IntegerRegister::PageNo => context.pageno = value,
|
||||
IntegerRegister::DeadCycles => context.deadcycles = value,
|
||||
IntegerRegister::MaxDeadCycles => context.max_deadcycles = value,
|
||||
IntegerRegister::OutputPenalty => context.output_penalty = value,
|
||||
IntegerRegister::PrevGraf => context.prev_graf = value,
|
||||
IntegerRegister::InsertionCount(class) => {
|
||||
@@ -820,6 +829,7 @@ mod tests {
|
||||
output_penalty: 0,
|
||||
pageno: 1,
|
||||
deadcycles: 0,
|
||||
max_deadcycles: 25,
|
||||
prev_graf: 0,
|
||||
..OutputContext::default()
|
||||
}
|
||||
@@ -979,6 +989,16 @@ mod tests {
|
||||
assert_eq!(program.shipout_count(&mut context).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn maxdeadcycles_is_readable_and_assignable() {
|
||||
let program =
|
||||
OutputProgram::parse(r"\ifnum\maxdeadcycles=25\shipout\box255\fi\maxdeadcycles=3")
|
||||
.unwrap();
|
||||
let mut context = context(10);
|
||||
assert_eq!(program.shipout_count(&mut context).unwrap(), 1);
|
||||
assert_eq!(context.max_deadcycles, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ifnum_reads_negative_output_penalty() {
|
||||
let program =
|
||||
|
||||
Reference in new issue
Block a user