Expose hsize and the page box width to the output routine
This commit is contained in:
1 parent
49079f7e70
commit
23956a012b
5 files changed
+56
-4
No files matched your search
@@ -32,6 +32,8 @@ pub struct OutputContext {
|
||||
pub page_shrink: i64,
|
||||
/// TeX `\vbadness`: badness of the break that produced the page.
|
||||
pub vbadness: i64,
|
||||
/// TeX `\hsize`: width of the page box handed to the output routine.
|
||||
pub hsize: i64,
|
||||
/// TeX `\vsize`: the configured page height.
|
||||
pub vsize: i64,
|
||||
/// TeX `\topskip`.
|
||||
@@ -70,6 +72,7 @@ impl Default for OutputContext {
|
||||
page_fill_stretch: 0,
|
||||
page_filll_stretch: 0,
|
||||
page_shrink: 0,
|
||||
hsize: 0,
|
||||
vbadness: 0,
|
||||
vsize: 0,
|
||||
top_skip: 0,
|
||||
@@ -242,6 +245,7 @@ fn parse_arithmetic_target(
|
||||
let class = parse_insertion_class(tokens, index, "\\skip", true)?;
|
||||
Ok(ArithmeticTarget::Dimension(Register::InsertionSkip(class)))
|
||||
}
|
||||
"hsize" => Ok(ArithmeticTarget::Dimension(Register::Hsize)),
|
||||
"vsize" => Ok(ArithmeticTarget::Dimension(Register::Vsize)),
|
||||
other => Err(format!("unsupported arithmetic target \\{other}")),
|
||||
}
|
||||
@@ -261,9 +265,12 @@ enum Register {
|
||||
BoxHeight255,
|
||||
/// TeX `\dp255`: depth of the page box handed to the output routine.
|
||||
BoxDepth255,
|
||||
/// TeX `\wd255`: width of the page box handed to the output routine.
|
||||
BoxWidth255,
|
||||
Vsize,
|
||||
TopSkip,
|
||||
MaxDepth,
|
||||
Hsize,
|
||||
InsertionDimen(u8),
|
||||
InsertionSkip(u8),
|
||||
}
|
||||
@@ -283,9 +290,11 @@ impl Dimension {
|
||||
Register::PageShrink => context.page_shrink,
|
||||
Register::BoxHeight255 => context.page_total,
|
||||
Register::BoxDepth255 => context.page_depth,
|
||||
Register::BoxWidth255 => context.hsize,
|
||||
Register::Vsize => context.vsize,
|
||||
Register::TopSkip => context.top_skip,
|
||||
Register::MaxDepth => context.max_depth,
|
||||
Register::Hsize => context.hsize,
|
||||
Register::InsertionDimen(class) => context.insertion_dimens[class as usize],
|
||||
Register::InsertionSkip(class) => context.insertion_skips[class as usize],
|
||||
},
|
||||
@@ -807,6 +816,12 @@ fn parse_dimension(tokens: &[Token], index: &mut usize) -> Result<Dimension, Str
|
||||
expect_box_255(tokens, index, "\\dp")?;
|
||||
return Ok(Dimension::Register(Register::BoxDepth255));
|
||||
}
|
||||
"wd" => {
|
||||
*index += 1;
|
||||
expect_box_255(tokens, index, "\\wd")?;
|
||||
return Ok(Dimension::Register(Register::BoxWidth255));
|
||||
}
|
||||
"hsize" => Register::Hsize,
|
||||
"vsize" => Register::Vsize,
|
||||
"topskip" => Register::TopSkip,
|
||||
"maxdepth" => Register::MaxDepth,
|
||||
@@ -995,6 +1010,7 @@ fn write_dimension(
|
||||
context.insertion_skips[class as usize] = value;
|
||||
}
|
||||
Register::Vsize => context.vsize = value,
|
||||
Register::BoxWidth255 | Register::Hsize => context.hsize = value,
|
||||
other => return Err(format!("cannot assign to page register {other:?}")),
|
||||
}
|
||||
Ok(())
|
||||
@@ -1117,6 +1133,17 @@ mod tests {
|
||||
assert_eq!(context.pageno, 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_routine_reads_hsize_and_the_page_box_width() {
|
||||
let program = OutputProgram::parse(
|
||||
"\\ifdim\\hsize=480pt\\shipout\\box255\\fi\\ifdim\\wd255=480pt\\shipout\\box255\\fi",
|
||||
)
|
||||
.unwrap();
|
||||
let mut context = context(10 * 65_536);
|
||||
context.hsize = 480 * 65_536;
|
||||
assert_eq!(program.shipout_count(&mut context).unwrap(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_routine_can_assign_registers() {
|
||||
let mut context = context(0);
|
||||
|
||||
Reference in new issue
Block a user