From a1c2aefbbacadc98123096a44ade8631b4c7daf5 Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 23 Nov 2026 01:14:54 +0100 Subject: [PATCH] fix(pdf): a line landing exactly on the text floor stays on its page FLOOR_EPSILON on the ensure_room test; four-long keeps its last line on page 1. wasm gzip (size test) 596738 B. --- crates/core/src/pdf/write/layout/observation.rs | 6 +++++- crates/core/tests/pdf_proportions.rs | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/core/src/pdf/write/layout/observation.rs b/crates/core/src/pdf/write/layout/observation.rs index ddfe0e77..1e2f5674 100644 --- a/crates/core/src/pdf/write/layout/observation.rs +++ b/crates/core/src/pdf/write/layout/observation.rs @@ -157,10 +157,14 @@ struct PageHead<'h> { severity: Option, } +/// The fit branch of `row_budget` sizes the images so the last line lands exactly on the floor; +/// float accumulation must not push it onto a new page (the census keeps a 1 pt clearance anyway). +const FLOOR_EPSILON: f64 = 1e-6; + /// Opens a continuation page when a line with `below` points of text under its baseline would /// go under the floor: never into the footer, never off the page (R2). fn ensure_room(layout: &mut Layout<'_>, cursor: &mut Cursor, head: &PageHead<'_>, below: f64) { - if cursor.y - below >= TEXT_FLOOR_Y { + if cursor.y - below >= TEXT_FLOOR_Y - FLOOR_EPSILON { return; } let page = layout.log.add_page(); diff --git a/crates/core/tests/pdf_proportions.rs b/crates/core/tests/pdf_proportions.rs index b7e22f44..0e811c3b 100644 --- a/crates/core/tests/pdf_proportions.rs +++ b/crates/core/tests/pdf_proportions.rs @@ -774,6 +774,14 @@ fn every_reference_case_passes_the_census() { } } +#[test] +fn four_long_keeps_its_last_line_on_the_floor_of_the_first_page() { + let drawn = draw(&reference_case("four-long")); + // One observation page and the conclusion. + assert_eq!(drawn.pages.len(), 2); + assert_clean(&drawn); +} + fn color(c: &faunosteo_core::pdf::write::draw_log::Rgb) -> Value { json!({ "type": "RGB", "red": c.red, "green": c.green, "blue": c.blue }) }