Expose the page box height and depth to the output routine
This commit is contained in:
1 parent
70b360e50e
commit
be23fe9686
4 files changed
+49
-4
No files matched your search
@@ -5905,6 +5905,23 @@ mod tests {
|
||||
assert_eq!(page_prev_graf(&empty), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_routine_reads_the_page_box_height() {
|
||||
let pt = 65_536;
|
||||
let mut document = Document::new(
|
||||
100 * pt,
|
||||
vec![
|
||||
Unit::rule(1, 10 * pt, 40 * pt),
|
||||
Unit::penalty(2, -10_000),
|
||||
Unit::rule(3, 10 * pt, 70 * pt),
|
||||
],
|
||||
);
|
||||
document.output_routine = Some(r"\ifdim\ht255>50pt\shipout\box255\else\relax\fi".into());
|
||||
let engine = Engine::layout_paged(&document).expect("paged layout");
|
||||
assert_eq!(engine.pages().len(), 1);
|
||||
assert_eq!(item_height(&engine.pages()[0].items[0]), 70 * pt);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_register_assignments_persist_across_pages() {
|
||||
let mut document = Document::new(
|
||||
|
||||
@@ -185,6 +185,10 @@ enum Register {
|
||||
PageFillStretch,
|
||||
PageFilllStretch,
|
||||
PageShrink,
|
||||
/// TeX `\ht255`: height of the page box handed to the output routine.
|
||||
BoxHeight255,
|
||||
/// TeX `\dp255`: depth of the page box handed to the output routine.
|
||||
BoxDepth255,
|
||||
Vsize,
|
||||
TopSkip,
|
||||
MaxDepth,
|
||||
@@ -205,6 +209,8 @@ impl Dimension {
|
||||
Register::PageFillStretch => context.page_fill_stretch,
|
||||
Register::PageFilllStretch => context.page_filll_stretch,
|
||||
Register::PageShrink => context.page_shrink,
|
||||
Register::BoxHeight255 => context.page_total,
|
||||
Register::BoxDepth255 => context.page_depth,
|
||||
Register::Vsize => context.vsize,
|
||||
Register::TopSkip => context.top_skip,
|
||||
Register::MaxDepth => context.max_depth,
|
||||
@@ -609,6 +615,17 @@ fn parse_integer(tokens: &[Token], index: &mut usize) -> Result<Integer, String>
|
||||
Ok(integer)
|
||||
}
|
||||
|
||||
/// Reads the box number after `\\ht`/`\\dp`; only box 255 is modelled.
|
||||
fn expect_box_255(tokens: &[Token], index: &mut usize, name: &str) -> Result<(), String> {
|
||||
match tokens.get(*index) {
|
||||
Some(Token::Number { value, unit }) if *value == 255.0 && unit.is_none() => {
|
||||
*index += 1;
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(format!("{name} only supports box 255")),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_dimension(tokens: &[Token], index: &mut usize) -> Result<Dimension, String> {
|
||||
let dimension = match tokens.get(*index) {
|
||||
Some(Token::Number { value, unit }) => {
|
||||
@@ -635,6 +652,16 @@ fn parse_dimension(tokens: &[Token], index: &mut usize) -> Result<Dimension, Str
|
||||
"pagefillstretch" => Register::PageFillStretch,
|
||||
"pagefilllstretch" => Register::PageFilllStretch,
|
||||
"pageshrink" => Register::PageShrink,
|
||||
"ht" => {
|
||||
*index += 1;
|
||||
expect_box_255(tokens, index, "\\ht")?;
|
||||
return Ok(Dimension::Register(Register::BoxHeight255));
|
||||
}
|
||||
"dp" => {
|
||||
*index += 1;
|
||||
expect_box_255(tokens, index, "\\dp")?;
|
||||
return Ok(Dimension::Register(Register::BoxDepth255));
|
||||
}
|
||||
"vsize" => Register::Vsize,
|
||||
"topskip" => Register::TopSkip,
|
||||
"maxdepth" => Register::MaxDepth,
|
||||
|
||||
Reference in new issue
Block a user