Expose page depth to the output routine
This commit is contained in:
1 parent
c8805af755
commit
62d3c4154e
4 files changed
+52
-7
No files matched your search
@@ -1650,6 +1650,7 @@ impl Engine {
|
||||
};
|
||||
let mut pages = Vec::new();
|
||||
let mut page_penalties = Vec::new();
|
||||
let mut page_depths = Vec::new();
|
||||
let mut held: BTreeMap<u8, Vec<VerticalItem>> = BTreeMap::new();
|
||||
for fragment in builder.build(&nodes) {
|
||||
let mut items = Vec::new();
|
||||
@@ -1707,6 +1708,7 @@ impl Engine {
|
||||
page.seal_in_place();
|
||||
pages.push(page);
|
||||
page_penalties.push(fragment.penalty);
|
||||
page_depths.push(fragment.depth);
|
||||
}
|
||||
|
||||
// Insertion material that did not fit its class limit on the page where
|
||||
@@ -1730,6 +1732,7 @@ impl Engine {
|
||||
page.seal_in_place();
|
||||
pages.push(page);
|
||||
page_penalties.push(0);
|
||||
page_depths.push(0);
|
||||
}
|
||||
if let Some(source) = &document.output_routine {
|
||||
let program = output::OutputProgram::parse(source).ok()?;
|
||||
@@ -1739,6 +1742,7 @@ impl Engine {
|
||||
let context = output::OutputContext {
|
||||
page_goal: document.page_goal,
|
||||
page_total,
|
||||
page_depth: page_depths.get(index).copied().unwrap_or(0),
|
||||
vsize: document.page_goal,
|
||||
top_skip: document.top_skip,
|
||||
max_depth: document.max_depth,
|
||||
@@ -5040,6 +5044,30 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_routine_sees_the_page_depth() {
|
||||
let math = Unit {
|
||||
id: 1,
|
||||
source: String::new(),
|
||||
items: vec![VerticalItem::Math {
|
||||
atom: crate::math::MathAtom::Symbol('x'),
|
||||
width: 10,
|
||||
height: 500_000,
|
||||
depth: 300_000,
|
||||
}],
|
||||
paragraph_style: None,
|
||||
};
|
||||
let mut document = Document::new(800_000, vec![math]);
|
||||
document.max_depth = 400_000;
|
||||
document.output_routine = Some(r"\ifdim\pagedepth>4pt\shipout\box255\fi".to_owned());
|
||||
let kept = Engine::layout_paged(&document).expect("math is page-buildable");
|
||||
assert_eq!(kept.pages().len(), 1);
|
||||
|
||||
document.max_depth = 0;
|
||||
let dropped = Engine::layout_paged(&document).expect("math is page-buildable");
|
||||
assert_eq!(dropped.pages().len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_layout_refuses_floats_but_places_insertions() {
|
||||
let floated = Document::new(100, vec![Unit::float(1, FloatPlacement::Top, 100, 20)]);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! Only the subset that decides *which* page box leaves the page builder is
|
||||
//! supported today: `\shipout\box255`, `\relax`, `\message{...}` and
|
||||
//! `\ifdim` comparisons over the page registers `\pagegoal`, `\pagetotal`,
|
||||
//! `\vsize`, `\topskip` and `\maxdepth`. Anything else is a parse error, which
|
||||
//! `\pagedepth`, `\vsize`, `\topskip` and `\maxdepth`. Anything else is a parse error, which
|
||||
//! makes `Engine::layout_paged` fall back to the scrolling builder.
|
||||
|
||||
use std::fmt;
|
||||
@@ -15,6 +15,8 @@ pub struct OutputContext {
|
||||
pub page_goal: i64,
|
||||
/// TeX `\pagetotal`: the height accumulated on the current page.
|
||||
pub page_total: i64,
|
||||
/// TeX `\pagedepth`: the depth of the page box so far.
|
||||
pub page_depth: i64,
|
||||
/// TeX `\vsize`: the configured page height.
|
||||
pub vsize: i64,
|
||||
/// TeX `\topskip`.
|
||||
@@ -96,6 +98,7 @@ enum Dimension {
|
||||
enum Register {
|
||||
PageGoal,
|
||||
PageTotal,
|
||||
PageDepth,
|
||||
Vsize,
|
||||
TopSkip,
|
||||
MaxDepth,
|
||||
@@ -108,6 +111,7 @@ impl Dimension {
|
||||
Self::Register(register) => match register {
|
||||
Register::PageGoal => context.page_goal,
|
||||
Register::PageTotal => context.page_total,
|
||||
Register::PageDepth => context.page_depth,
|
||||
Register::Vsize => context.vsize,
|
||||
Register::TopSkip => context.top_skip,
|
||||
Register::MaxDepth => context.max_depth,
|
||||
@@ -473,6 +477,7 @@ fn parse_dimension(tokens: &[Token], index: &mut usize) -> Result<Dimension, Str
|
||||
let register = match name.as_str() {
|
||||
"pagegoal" => Register::PageGoal,
|
||||
"pagetotal" => Register::PageTotal,
|
||||
"pagedepth" => Register::PageDepth,
|
||||
"vsize" => Register::Vsize,
|
||||
"topskip" => Register::TopSkip,
|
||||
"maxdepth" => Register::MaxDepth,
|
||||
@@ -560,6 +565,7 @@ mod tests {
|
||||
OutputContext {
|
||||
page_goal: 612 * 65_536,
|
||||
page_total,
|
||||
page_depth: 0,
|
||||
vsize: 612 * 65_536,
|
||||
top_skip: 10 * 65_536,
|
||||
max_depth: 0,
|
||||
@@ -575,6 +581,15 @@ mod tests {
|
||||
assert_eq!(program.shipout_count(&context(0)).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn page_depth_register_is_visible() {
|
||||
let program = OutputProgram::parse(r"\ifdim\pagedepth>4pt\shipout\box255\fi").unwrap();
|
||||
let mut deep = context(0);
|
||||
deep.page_depth = 5 * 65_536;
|
||||
assert_eq!(program.shipout_count(&deep).unwrap(), 1);
|
||||
assert_eq!(program.shipout_count(&context(0)).unwrap(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn conditional_ships_only_large_pages() {
|
||||
let program = OutputProgram::parse(r"\ifdim\pagetotal>50pt\shipout\box255\fi").unwrap();
|
||||
|
||||
Reference in new issue
Block a user