Let the output routine retarget later pages with vsize
This commit is contained in:
1 parent
3b99f93ab8
commit
c6ebbea58d
5 files changed
+188
-8
No files matched your search
@@ -92,6 +92,32 @@ impl OutputProgram {
|
||||
Ok(Self { ops })
|
||||
}
|
||||
|
||||
/// True when the routine assigns `\vsize`, so later page goals change.
|
||||
pub fn assigns_vsize(&self) -> bool {
|
||||
fn scan(ops: &[Op]) -> bool {
|
||||
ops.iter().any(|op| match op {
|
||||
Op::AssignDimension {
|
||||
register: Register::Vsize,
|
||||
..
|
||||
} => true,
|
||||
Op::IfDim {
|
||||
then_ops, else_ops, ..
|
||||
}
|
||||
| Op::IfNum {
|
||||
then_ops, else_ops, ..
|
||||
}
|
||||
| Op::IfOdd {
|
||||
then_ops, else_ops, ..
|
||||
} => scan(then_ops) || scan(else_ops),
|
||||
Op::IfCase {
|
||||
branches, else_ops, ..
|
||||
} => branches.iter().any(|branch| scan(branch)) || scan(else_ops),
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
scan(&self.ops)
|
||||
}
|
||||
|
||||
/// Execute the program for one page and return how many times it called
|
||||
/// `\shipout`.
|
||||
pub fn shipout_count(&self, context: &mut OutputContext) -> Result<usize, String> {
|
||||
@@ -383,7 +409,8 @@ fn parse_sequence(tokens: &[Token], index: &mut usize, stop: &[&str]) -> Result<
|
||||
}
|
||||
ops.push(Op::Message(text));
|
||||
}
|
||||
"pageno" | "deadcycles" | "outputpenalty" | "count" | "dimen" | "skip" => {
|
||||
"pageno" | "deadcycles" | "outputpenalty" | "count" | "dimen" | "skip"
|
||||
| "vsize" => {
|
||||
*index += 1;
|
||||
let (integer_register, dimension_register) = match name.as_str() {
|
||||
"pageno" => (Some(IntegerRegister::PageNo), None),
|
||||
@@ -397,6 +424,7 @@ fn parse_sequence(tokens: &[Token], index: &mut usize, stop: &[&str]) -> Result<
|
||||
let class = parse_insertion_class(tokens, index, "\\dimen", true)?;
|
||||
(None, Some(Register::InsertionDimen(class)))
|
||||
}
|
||||
"vsize" => (None, Some(Register::Vsize)),
|
||||
_ => {
|
||||
let class = parse_insertion_class(tokens, index, "\\skip", true)?;
|
||||
(None, Some(Register::InsertionSkip(class)))
|
||||
@@ -727,6 +755,7 @@ fn execute(ops: &[Op], context: &mut OutputContext, shipped: &mut usize) -> Resu
|
||||
Register::InsertionSkip(class) => {
|
||||
context.insertion_skips[*class as usize] = value;
|
||||
}
|
||||
Register::Vsize => context.vsize = value,
|
||||
other => {
|
||||
return Err(format!("cannot assign to page register {other:?}"));
|
||||
}
|
||||
@@ -810,6 +839,19 @@ mod tests {
|
||||
assert_eq!(program.shipout_count(&mut context(0)).unwrap(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_routine_can_assign_vsize() {
|
||||
let mut context = context(0);
|
||||
let program =
|
||||
OutputProgram::parse(r"\vsize=300pt\ifdim\vsize>200pt\shipout\box255\fi").unwrap();
|
||||
assert!(program.assigns_vsize());
|
||||
assert_eq!(program.shipout_count(&mut context).unwrap(), 1);
|
||||
assert_eq!(context.vsize, 300 * 65_536);
|
||||
|
||||
let plain = OutputProgram::parse(r"\shipout\box255").unwrap();
|
||||
assert!(!plain.assigns_vsize());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_routine_can_assign_registers() {
|
||||
let mut context = context(0);
|
||||
|
||||
Reference in new issue
Block a user