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 pages = Vec::new();
|
||||||
let mut page_penalties = Vec::new();
|
let mut page_penalties = Vec::new();
|
||||||
|
let mut page_depths = Vec::new();
|
||||||
let mut held: BTreeMap<u8, Vec<VerticalItem>> = BTreeMap::new();
|
let mut held: BTreeMap<u8, Vec<VerticalItem>> = BTreeMap::new();
|
||||||
for fragment in builder.build(&nodes) {
|
for fragment in builder.build(&nodes) {
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
@@ -1707,6 +1708,7 @@ impl Engine {
|
|||||||
page.seal_in_place();
|
page.seal_in_place();
|
||||||
pages.push(page);
|
pages.push(page);
|
||||||
page_penalties.push(fragment.penalty);
|
page_penalties.push(fragment.penalty);
|
||||||
|
page_depths.push(fragment.depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insertion material that did not fit its class limit on the page where
|
// Insertion material that did not fit its class limit on the page where
|
||||||
@@ -1730,6 +1732,7 @@ impl Engine {
|
|||||||
page.seal_in_place();
|
page.seal_in_place();
|
||||||
pages.push(page);
|
pages.push(page);
|
||||||
page_penalties.push(0);
|
page_penalties.push(0);
|
||||||
|
page_depths.push(0);
|
||||||
}
|
}
|
||||||
if let Some(source) = &document.output_routine {
|
if let Some(source) = &document.output_routine {
|
||||||
let program = output::OutputProgram::parse(source).ok()?;
|
let program = output::OutputProgram::parse(source).ok()?;
|
||||||
@@ -1739,6 +1742,7 @@ impl Engine {
|
|||||||
let context = output::OutputContext {
|
let context = output::OutputContext {
|
||||||
page_goal: document.page_goal,
|
page_goal: document.page_goal,
|
||||||
page_total,
|
page_total,
|
||||||
|
page_depth: page_depths.get(index).copied().unwrap_or(0),
|
||||||
vsize: document.page_goal,
|
vsize: document.page_goal,
|
||||||
top_skip: document.top_skip,
|
top_skip: document.top_skip,
|
||||||
max_depth: document.max_depth,
|
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]
|
#[test]
|
||||||
fn paged_layout_refuses_floats_but_places_insertions() {
|
fn paged_layout_refuses_floats_but_places_insertions() {
|
||||||
let floated = Document::new(100, vec![Unit::float(1, FloatPlacement::Top, 100, 20)]);
|
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
|
//! Only the subset that decides *which* page box leaves the page builder is
|
||||||
//! supported today: `\shipout\box255`, `\relax`, `\message{...}` and
|
//! supported today: `\shipout\box255`, `\relax`, `\message{...}` and
|
||||||
//! `\ifdim` comparisons over the page registers `\pagegoal`, `\pagetotal`,
|
//! `\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.
|
//! makes `Engine::layout_paged` fall back to the scrolling builder.
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@@ -15,6 +15,8 @@ pub struct OutputContext {
|
|||||||
pub page_goal: i64,
|
pub page_goal: i64,
|
||||||
/// TeX `\pagetotal`: the height accumulated on the current page.
|
/// TeX `\pagetotal`: the height accumulated on the current page.
|
||||||
pub page_total: i64,
|
pub page_total: i64,
|
||||||
|
/// TeX `\pagedepth`: the depth of the page box so far.
|
||||||
|
pub page_depth: i64,
|
||||||
/// TeX `\vsize`: the configured page height.
|
/// TeX `\vsize`: the configured page height.
|
||||||
pub vsize: i64,
|
pub vsize: i64,
|
||||||
/// TeX `\topskip`.
|
/// TeX `\topskip`.
|
||||||
@@ -96,6 +98,7 @@ enum Dimension {
|
|||||||
enum Register {
|
enum Register {
|
||||||
PageGoal,
|
PageGoal,
|
||||||
PageTotal,
|
PageTotal,
|
||||||
|
PageDepth,
|
||||||
Vsize,
|
Vsize,
|
||||||
TopSkip,
|
TopSkip,
|
||||||
MaxDepth,
|
MaxDepth,
|
||||||
@@ -108,6 +111,7 @@ impl Dimension {
|
|||||||
Self::Register(register) => match register {
|
Self::Register(register) => match register {
|
||||||
Register::PageGoal => context.page_goal,
|
Register::PageGoal => context.page_goal,
|
||||||
Register::PageTotal => context.page_total,
|
Register::PageTotal => context.page_total,
|
||||||
|
Register::PageDepth => context.page_depth,
|
||||||
Register::Vsize => context.vsize,
|
Register::Vsize => context.vsize,
|
||||||
Register::TopSkip => context.top_skip,
|
Register::TopSkip => context.top_skip,
|
||||||
Register::MaxDepth => context.max_depth,
|
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() {
|
let register = match name.as_str() {
|
||||||
"pagegoal" => Register::PageGoal,
|
"pagegoal" => Register::PageGoal,
|
||||||
"pagetotal" => Register::PageTotal,
|
"pagetotal" => Register::PageTotal,
|
||||||
|
"pagedepth" => Register::PageDepth,
|
||||||
"vsize" => Register::Vsize,
|
"vsize" => Register::Vsize,
|
||||||
"topskip" => Register::TopSkip,
|
"topskip" => Register::TopSkip,
|
||||||
"maxdepth" => Register::MaxDepth,
|
"maxdepth" => Register::MaxDepth,
|
||||||
@@ -560,6 +565,7 @@ mod tests {
|
|||||||
OutputContext {
|
OutputContext {
|
||||||
page_goal: 612 * 65_536,
|
page_goal: 612 * 65_536,
|
||||||
page_total,
|
page_total,
|
||||||
|
page_depth: 0,
|
||||||
vsize: 612 * 65_536,
|
vsize: 612 * 65_536,
|
||||||
top_skip: 10 * 65_536,
|
top_skip: 10 * 65_536,
|
||||||
max_depth: 0,
|
max_depth: 0,
|
||||||
@@ -575,6 +581,15 @@ mod tests {
|
|||||||
assert_eq!(program.shipout_count(&context(0)).unwrap(), 1);
|
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]
|
#[test]
|
||||||
fn conditional_ships_only_large_pages() {
|
fn conditional_ships_only_large_pages() {
|
||||||
let program = OutputProgram::parse(r"\ifdim\pagetotal>50pt\shipout\box255\fi").unwrap();
|
let program = OutputProgram::parse(r"\ifdim\pagetotal>50pt\shipout\box255\fi").unwrap();
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
|
|||||||
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
||||||
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
||||||
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
||||||
PDF opt-in with `?engine=route-d`). 353 workspace tests are green and no oracle
|
PDF opt-in with `?engine=route-d`). 355 workspace tests are green and no oracle
|
||||||
fixture is ignored.
|
fixture is ignored.
|
||||||
|
|
||||||
Known gaps, in dependency order:
|
Known gaps, in dependency order:
|
||||||
@@ -237,7 +237,7 @@ Scope:
|
|||||||
- glue setting in vertical lists (ragged/flush bottom), `\vsize`, `\voffset`,
|
- glue setting in vertical lists (ragged/flush bottom), `\vsize`, `\voffset`,
|
||||||
`\topskip`, `\maxdepth`, `\splittopskip`, `\splitmaxdepth`;
|
`\topskip`, `\maxdepth`, `\splittopskip`, `\splitmaxdepth`;
|
||||||
- TeX page builder: candidate breakpoints, cost = badness + penalty, page goal
|
- TeX page builder: candidate breakpoints, cost = badness + penalty, page goal
|
||||||
recomputation as insertions arrive, `\pagegoal`, `\pagetotal`,
|
recomputation as insertions arrive, `\pagegoal`, `\pagetotal`, `\pagedepth`,
|
||||||
`\pagestretch`, `\pagefilstretch`, `\pagefillstretch`, `\pagefilllstretch`,
|
`\pagestretch`, `\pagefilstretch`, `\pagefillstretch`, `\pagefilllstretch`,
|
||||||
`\pageshrink`, `\pagedepth`;
|
`\pageshrink`, `\pagedepth`;
|
||||||
- marks: `\mark`, `\botmark`, `\firstmark`, `\topmark`, `\marks` (marks are
|
- marks: `\mark`, `\botmark`, `\firstmark`, `\topmark`, `\marks` (marks are
|
||||||
|
|||||||
+6
-4
@@ -239,9 +239,11 @@ oracle fixture is ignored.
|
|||||||
in the page hash. `OutputRoutine::shipout` runs before sealing and may
|
in the page hash. `OutputRoutine::shipout` runs before sealing and may
|
||||||
mutate each page; this models the `\output` stage in Rust. The interpreted
|
mutate each page; this models the `\output` stage in Rust. The interpreted
|
||||||
subset lives in `output::OutputProgram` (`Document::output_routine`), which
|
subset lives in `output::OutputProgram` (`Document::output_routine`), which
|
||||||
understands `\shipout\box255`, `\relax`, `\message{...}` and `\ifdim` /
|
understands `\shipout\box255`, `\relax`, `\message{...}`, `\ifdim`,
|
||||||
`\else` / `\fi` over the page registers `\pagegoal`, `\pagetotal`, `\vsize`,
|
`\ifnum`, `\ifodd` and `\ifcase` over the page registers `\pagegoal`,
|
||||||
`\topskip` and `\maxdepth`; it cannot yet change page goals. Top `Float`
|
`\pagetotal`, `\pagedepth`, `\vsize`, `\topskip`, `\maxdepth`,
|
||||||
|
`\outputpenalty`, `\pageno` and `\deadcycles`; it cannot yet change page
|
||||||
|
goals. Top `Float`
|
||||||
material is deferred to the next page when it arrives late; bottom
|
material is deferred to the next page when it arrives late; bottom
|
||||||
floats reserve height on the current page and must satisfy
|
floats reserve height on the current page and must satisfy
|
||||||
`Document.text_fraction_percent` (default 50%); a page holding only floats
|
`Document.text_fraction_percent` (default 50%); a page holding only floats
|
||||||
@@ -332,7 +334,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
|
|||||||
|
|
||||||
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`) supplies advances, kerns, ligatures, and italic correction for layout, while the display list and PDF select the matching Liberation face. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`) supplies advances, kerns, ligatures, and italic correction for layout, while the display list and PDF select the matching Liberation face. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
||||||
|
|
||||||
The crate currently has 235 unit tests plus seven route-D integration tests and thirteen oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 353 tests (235 route-D unit, 7 route-D integration, 13 oracle, 71 v1 integration, 20 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
|
The crate currently has 237 unit tests plus seven route-D integration tests and thirteen oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 355 tests (237 route-D unit, 7 route-D integration, 13 oracle, 71 v1 integration, 20 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
|
||||||
|
|
||||||
### M0 incremental demo
|
### M0 incremental demo
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user