Ship float-heavy pages without body material
This commit is contained in:
1 parent
594a57e414
commit
66dfb10b60
4 files changed
+82
-4
No files matched your search
@@ -1965,6 +1965,7 @@ impl Engine {
|
||||
top_number: usize::from(document.top_number),
|
||||
bottom_number: usize::from(document.bottom_number),
|
||||
total_number: usize::from(document.total_number),
|
||||
float_page_fraction_percent: document.float_page_fraction_percent,
|
||||
ragged_bottom: document.ragged_bottom,
|
||||
}
|
||||
}
|
||||
@@ -5798,6 +5799,28 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_layout_honours_float_page_fraction() {
|
||||
let mut document = Document::new(
|
||||
100,
|
||||
vec![
|
||||
Unit::float(1, FloatPlacement::Top, 100, 60),
|
||||
Unit::rule(2, 100, 10),
|
||||
],
|
||||
);
|
||||
document.text_fraction_percent = 0;
|
||||
document.float_page_fraction_percent = 50;
|
||||
let layout = Engine::layout_paged(&document).expect("float page builds");
|
||||
assert_eq!(layout.pages().len(), 2);
|
||||
assert!(layout.pages()[0].items.is_empty());
|
||||
assert_eq!(layout.pages()[0].floats.len(), 1);
|
||||
|
||||
document.float_page_fraction_percent = 90;
|
||||
let layout = Engine::layout_paged(&document).expect("shared page builds");
|
||||
assert_eq!(layout.pages().len(), 1);
|
||||
assert_eq!(layout.pages()[0].items.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_float_reserves_text_float_sep_in_the_display_list() {
|
||||
let mut document = Document::new(
|
||||
|
||||
@@ -159,6 +159,9 @@ pub struct PageBuilder {
|
||||
pub bottom_number: usize,
|
||||
/// TeX `\totalnumber`: maximum floats, of any placement, on one page.
|
||||
pub total_number: usize,
|
||||
/// TeX `\floatpagefraction`: percent of the page floats must occupy
|
||||
/// before the body is pushed to the next page.
|
||||
pub float_page_fraction_percent: u8,
|
||||
/// TeX `\raggedbottom` (default) versus `\flushbottom`.
|
||||
pub ragged_bottom: bool,
|
||||
}
|
||||
@@ -176,6 +179,7 @@ impl PageBuilder {
|
||||
top_number: 2,
|
||||
bottom_number: 1,
|
||||
total_number: 12,
|
||||
float_page_fraction_percent: 50,
|
||||
ragged_bottom: true,
|
||||
}
|
||||
}
|
||||
@@ -263,6 +267,37 @@ impl PageBuilder {
|
||||
height: box_height,
|
||||
depth: box_depth,
|
||||
} => {
|
||||
// TeX ships a page that is mostly floats on its own; the
|
||||
// body starts on the next page instead of sharing it.
|
||||
if has_float
|
||||
&& !has_body
|
||||
&& height * 100
|
||||
>= i64::from(self.float_page_fraction_percent) * self.page_goal
|
||||
{
|
||||
let end = index.max(start);
|
||||
let badness =
|
||||
self.badness(height, reserved + bottom, stretch, shrink, stretch_order);
|
||||
let fragment = self.fragment(
|
||||
start,
|
||||
end,
|
||||
height,
|
||||
depth,
|
||||
stretch,
|
||||
shrink,
|
||||
stretch_order,
|
||||
badness,
|
||||
badness,
|
||||
0,
|
||||
bottom,
|
||||
order_stretches(&nodes[start..end]),
|
||||
self.insertion_space(nodes, start, end, held),
|
||||
);
|
||||
return Some((
|
||||
fragment,
|
||||
index,
|
||||
self.insertion_overflow(nodes, start, end, held),
|
||||
));
|
||||
}
|
||||
let contribution = if first_box {
|
||||
(*box_height).max(self.top_skip)
|
||||
+ if has_float {
|
||||
@@ -1035,6 +1070,26 @@ mod tests {
|
||||
assert_eq!(pages[1].bottom, 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_page_fraction_pushes_the_body_to_the_next_page() {
|
||||
let nodes = vec![
|
||||
VerticalNode::Float { height: 60 },
|
||||
VerticalNode::Box {
|
||||
height: 10,
|
||||
depth: 0,
|
||||
},
|
||||
];
|
||||
let mut builder = PageBuilder::new(100);
|
||||
builder.float_page_fraction_percent = 50;
|
||||
let pages = builder.build(&nodes);
|
||||
assert_eq!(pages.len(), 2);
|
||||
assert_eq!((pages[0].start, pages[0].end), (0, 1));
|
||||
assert_eq!(pages[1].start, 1);
|
||||
|
||||
builder.float_page_fraction_percent = 90;
|
||||
assert_eq!(builder.build(&nodes).len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bottom_fraction_caps_bottom_float_space() {
|
||||
let builder = PageBuilder {
|
||||
|
||||
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
|
||||
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
||||
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
|
||||
PDF opt-in with `?engine=route-d`). 388 workspace tests are green and no oracle
|
||||
PDF opt-in with `?engine=route-d`). 401 workspace tests are green and no oracle
|
||||
fixture is ignored.
|
||||
|
||||
Known gaps, in dependency order:
|
||||
|
||||
+3
-3
@@ -116,7 +116,7 @@ and justification.
|
||||
| --- | --- | --- |
|
||||
| M0 | vertical list, page builder, checkpoint, page hash, edit demo | edit on page 2 rebuilds only page 2 |
|
||||
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics, TeX Live en-US hyphenation, TeX demerits and tolerance passes, `\hangindent`/`\parshape`, `\parfillskip`, sentence spacing, `\spaceskip`/`\xspaceskip`, `\raggedright` (infinite `\rightskip`), `\looseness`, `\baselineskip`/`\lineskip`/`\parskip` interline glue, pdfLaTeX oracle matrix 90-240pt plus register, geometry, `\sfcode` and vertical-glue fixtures; generic fil glue and `\prevgraf` next |
|
||||
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; `page::PageBuilder` scores candidate breakpoints with TeX page badness, glue setting (with `\raggedbottom`/`\flushbottom` applied when pages are materialised, and TeX glue orders `\vfil`/`\vfill`/`\vfilll` honoured so only the highest order with stretch is used), `\topskip`/`\maxdepth`, and `Engine::layout_paged` uses it for documents whose units are single vertical items, placing top and bottom floats (with `\floatsep`, a `\bottomfraction` cap and the `\topnumber`/`\bottomnumber`/`\totalnumber` limits) and insertion classes on that path, while in-text floats flow inline as body material; paged layouts replay edits from the edited unit's page and fall back to a full rebuild only when insertions or an interpreted `\output` are present; `\output` is interpreted for a `\shipout`/`\ifdim`/`\ifnum`/`\ifodd`/`\ifcase` subset; `\pageno`, `\outputpenalty` and `\deadcycles` are readable registers, insertion class registers `\count<n>`/`\dimen<n>`/`\skip<n>` read the configured multiplier, maximum height and skip of class `n` (with `\count0` reading `\pageno`), `PageFragment::penalty` carries the break penalty, and `PageFragment::stretches` records glue stretch per TeX order so `\pagefilstretch`/`\pagefillstretch`/`\pagefilllstretch` are readable in the output routine |
|
||||
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; `page::PageBuilder` scores candidate breakpoints with TeX page badness, glue setting (with `\raggedbottom`/`\flushbottom` applied when pages are materialised, and TeX glue orders `\vfil`/`\vfill`/`\vfilll` honoured so only the highest order with stretch is used), `\topskip`/`\maxdepth`, and `Engine::layout_paged` uses it for documents whose units are single vertical items, placing top and bottom floats (with `\floatsep`, a `\bottomfraction` cap and the `\topnumber`/`\bottomnumber`/`\totalnumber` limits, with `\floatpagefraction` deciding when a float-heavy page ships without body) and insertion classes on that path, while in-text floats flow inline as body material; paged layouts replay edits from the edited unit's page and fall back to a full rebuild only when insertions or an interpreted `\output` are present; `\output` is interpreted for a `\shipout`/`\ifdim`/`\ifnum`/`\ifodd`/`\ifcase` subset; `\pageno`, `\outputpenalty` and `\deadcycles` are readable registers, insertion class registers `\count<n>`/`\dimen<n>`/`\skip<n>` read the configured multiplier, maximum height and skip of class `n` (with `\count0` reading `\pageno`), `PageFragment::penalty` carries the break penalty, and `PageFragment::stretches` records glue stretch per TeX order so `\pagefilstretch`/`\pagefillstretch`/`\pagefilllstretch` are readable in the output routine |
|
||||
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | **partial**: source parsing, natural column widths, spans, rule rows, 10pt display-list painting and row-level page splitting; no booktabs/longtable parity yet |
|
||||
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | **partial**: token parser, atom boxes with CMR10 metrics, delimiter scaling, accents and a display-list painter; no CMEX size variants or TeX math spacing classes yet |
|
||||
| M5 | NFSS/TFM metrics, CM/Latin Modern | same line/page breaks as reference |
|
||||
@@ -255,7 +255,7 @@ oracle fixture is ignored.
|
||||
of a page and bottom `Float` material at the page bottom: a late top float
|
||||
starts the next page, a bottom float that cannot fit the remaining body
|
||||
space is deferred, stacked bottom floats reserve `\floatsep`, and
|
||||
`\bottomfraction` caps the bottom float share. Route-D preview/PDF draw
|
||||
`\bottomfraction` caps the bottom float share, and a page whose top floats reach `\floatpagefraction` ships without body material. Route-D preview/PDF draw
|
||||
pages through `display_list_with_layout` so the body clears
|
||||
`\textfloatsep` / the bottom float area; the scrolling builder still
|
||||
reserves height for bottom floats against `Document.text_fraction_percent`
|
||||
@@ -346,7 +346,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.
|
||||
|
||||
The crate currently has 275 unit tests plus seven route-D integration tests and seventeen oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 399 tests (275 route-D unit, 7 route-D integration, 17 oracle, 71 v1 integration, 22 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
|
||||
The crate currently has 277 unit tests plus seven route-D integration tests and seventeen oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 401 tests (277 route-D unit, 7 route-D integration, 17 oracle, 71 v1 integration, 22 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
Reference in new issue
Block a user