Expose the page box height and depth to the output routine

This commit is contained in:
gloamxun committed 2026-10-23 13:24:14 +08:00
1 parent 70b360e50e
commit be23fe9686
4 files changed
+49 -4

No files matched your search

+27
View File
@@ -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,