Expose hsize and the page box width to the output routine

This commit is contained in:
gloamxun committed 2026-10-24 00:14:55 +08:00
1 parent 49079f7e70
commit 23956a012b
5 files changed
+56 -4

No files matched your search

+24
View File
@@ -610,6 +610,9 @@ pub struct Document {
/// TeX `\paperheight`: height of the output page.
#[serde(default = "default_paper_height")]
pub paper_height: i64,
/// TeX `\hsize`: width of the page box handed to the output routine.
#[serde(default = "default_text_width")]
pub text_width: i64,
/// TeX-like `\topskip`: distance from the page top to the first baseline.
#[serde(default)]
pub top_skip: i64,
@@ -705,6 +708,10 @@ fn default_paper_height() -> i64 {
792 * 65_536
}
fn default_text_width() -> i64 {
345 * 65_536
}
fn default_text_fraction() -> u8 {
50
}
@@ -765,6 +772,7 @@ impl Document {
page_breaks: Vec::new(),
paper_width: default_paper_width(),
paper_height: default_paper_height(),
text_width: default_text_width(),
top_skip: 0,
max_depth: 0,
text_fraction_percent: default_text_fraction(),
@@ -2148,6 +2156,7 @@ impl Engine {
page_filll_stretch: page_filll_stretches.get(index).copied().unwrap_or(0),
page_shrink: page_shrinks.get(index).copied().unwrap_or(0),
vbadness: page_badnesses.get(index).copied().unwrap_or(10_000),
hsize: document.text_width,
vsize: document.page_goal,
top_skip: document.top_skip,
max_depth: document.max_depth,
@@ -2349,6 +2358,7 @@ impl Engine {
page_filll_stretch: fragment.stretches[3],
page_shrink: fragment.shrink,
vbadness: fragment.badness,
hsize: document.text_width,
vsize: goal,
top_skip: document.top_skip,
max_depth: document.max_depth,
@@ -6508,6 +6518,20 @@ mod tests {
assert_eq!(dropped.pages().len(), 0);
}
#[test]
fn output_routine_sees_the_text_width() {
let rule = Unit::rule(1, 100 * 65_536, 10 * 65_536);
let mut document = Document::new(100 * 65_536, vec![rule]);
document.text_width = 320 * 65_536;
document.output_routine = Some(r"\ifdim\hsize=320pt\shipout\box255\fi".to_owned());
let kept = Engine::layout_paged(&document).expect("rule is page-buildable");
assert_eq!(kept.pages().len(), 1);
document.output_routine = Some(r"\ifdim\wd255=319pt\shipout\box255\fi".to_owned());
let dropped = Engine::layout_paged(&document).expect("rule is page-buildable");
assert_eq!(dropped.pages().len(), 0);
}
#[test]
fn paged_layout_expands_multi_item_units_and_places_insertions() {
let stacked = Document::new(