diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index cfb8568..db086a7 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -684,6 +684,21 @@ impl Engine { page_floats: current.floats.clone(), }); for item in &unit.items { + if !matches!( + item, + VerticalItem::Float(_) + | VerticalItem::Penalty(_) + | VerticalItem::Mark(_) + | VerticalItem::Insertion(_) + ) && current.items.is_empty() + && !current.floats.is_empty() + && document.page_goal - used + < document.text_fraction_percent as i64 * document.page_goal / 100 + { + pages.push(std::mem::replace(&mut current, Page::empty())); + used = document.top_skip; + insertion_height = 0; + } match item { VerticalItem::Rule { height, .. } => { if current.items.is_empty() { @@ -949,6 +964,21 @@ impl Engine { page_floats: current.floats.clone(), }); for item in &unit.items { + if !matches!( + item, + VerticalItem::Float(_) + | VerticalItem::Penalty(_) + | VerticalItem::Mark(_) + | VerticalItem::Insertion(_) + ) && current.items.is_empty() + && !current.floats.is_empty() + && document.page_goal - used + < document.text_fraction_percent as i64 * document.page_goal / 100 + { + pages.push(std::mem::replace(&mut current, Page::empty())); + used = document.top_skip; + insertion_height = 0; + } match item { VerticalItem::Rule { height, .. } => { if current.items.is_empty() { @@ -1330,6 +1360,32 @@ mod tests { assert_eq!(engine.layout.pages[1].items.len(), 1); } + #[test] + fn a_large_top_float_gets_a_float_page() { + let mut document = Document::new(100, Vec::new()); + document.top_skip = 0; + document.units.push(Unit::float_with_content( + 1, + FloatPlacement::Top, + 50, + 60, + vec![VerticalItem::Rule { + width: 50, + height: 60, + }], + )); + document.units.push(Unit::vertical( + 2, + vec![VerticalItem::Box(VerticalBox { + width: 10, + height: 10, + })], + )); + let engine = Engine::layout(&document); + assert_eq!(engine.pages().len(), 2); + assert!(engine.pages()[0].items.is_empty()); + assert_eq!(engine.pages()[0].floats.len(), 1); + } #[test] fn text_fraction_keeps_a_bottom_float_off_a_mostly_empty_page() { let mut document = Document::new( diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index b9fed4a..e719569 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -175,8 +175,8 @@ a single cost function. an interpreted token list, and cannot yet change page goals. Top `Float` material is deferred to the next page when it arrives late; bottom floats reserve height on the current page and must satisfy - `Document.text_fraction_percent` (default 50%). Dedicated float pages are - not implemented yet. + `Document.text_fraction_percent` (default 50%); a page holding only floats + is sealed once it leaves less than that fraction for text. - No macro state, output routine, math, fonts or PDF output in the new core yet. - The v1 server and project API still use `src/rust_typeset` and are unchanged.