From c09ce0b204c757134399fa946d7b23949dbbba64 Mon Sep 17 00:00:00 2001 From: mtlcl410 <2368091+mtlcl410@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:02:23 +0800 Subject: [PATCH] M12: a growable lr-tb XFA subform is split at a page break, not moved whole A flowing lr-tb or rl-tb subform without a height, laid out as one block, moved whole to the next page when it didn't fit what was left of this one. A subform is splittable "in margins and where consensus exists among contained objects" (XFA 3.3 p. 1520), and readers start it on the page and carry the rest over. It now does the same, as a block taller than a page already did. One with a height still moves whole. With the row-height fix before it, a public evaluation form's sections shrank enough to fit a page, so they moved whole and left page 1 nearly empty (3 pages, where readers lay the form out on 2). It is 2 again. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CBVyQEwtmEw3mS1MoAiwrK --- crates/xfa/src/layout/flow.rs | 7 ++++++- crates/xfa/src/tests.rs | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/xfa/src/layout/flow.rs b/crates/xfa/src/layout/flow.rs index 8f656d7eaf..d83842c26b 100644 --- a/crates/xfa/src/layout/flow.rs +++ b/crates/xfa/src/layout/flow.rs @@ -8,7 +8,12 @@ impl Layouter<'_> { /// content area (a positioned or fixed-height subform holding more than a page). fn flow_block(&mut self, node: &Node, x: f64, (w, h): (f64, f64), ctx: &Ctx, depth: usize, sib: usize) -> Result<(), XfaError> { let (rect, y, _) = self.cursor(); - if y + h > rect.bottom() + 0.01 && h <= rect.h + 0.01 { + // A growable flowing subform (`lr-tb`/`rl-tb`, no `h`) is split where its objects allow + // ("splittable: in margins and where consensus exists among contained objects", XFA 3.3 + // p. 1520), so it starts here and the rest goes on in the next content area, as one + // taller than a content area does. Anything else that fits one moves there whole. + let flows_on = matches!(node, Node::Subform(s) if matches!(s.layout, Layout::LrTb | Layout::RlTb) && s.common.h.is_none()); + if !flows_on && y + h > rect.bottom() + 0.01 && h <= rect.h + 0.01 { self.make_room(h, 0.0)?; } let (rect, y, _) = self.cursor(); diff --git a/crates/xfa/src/tests.rs b/crates/xfa/src/tests.rs index c16b56b4de..cfef0a372c 100644 --- a/crates/xfa/src/tests.rs +++ b/crates/xfa/src/tests.rs @@ -4118,3 +4118,28 @@ fn an_empty_multiline_field_with_a_minimum_height_starts_there() { assert!(height(r#"minH="7.62mm""#, Some(&"word ".repeat(80))) > 40.0, "text grows it"); assert!(height("", None) > 38.0, "three lines without a minimum: {}", height("", None)); } + +/// A growable `lr-tb` subform that doesn't fit what is left of the page is split there (XFA 3.3 +/// p. 1520), its first rows on this page and the rest on the next, as a public evaluation form's +/// sections are; one with a height, a positioned one, still moves whole. +#[test] +fn a_growable_lr_tb_subform_is_split_at_the_page_break() { + let xml = |attrs: &str| { + let rows: String = (0..6).map(|i| format!(r#""#)).collect(); + format!( + r#""# + ) + }; + let pages_of = |attrs: &str| { + let t = crate::parse(&xml(attrs)).unwrap().0; + let form = crate::layout::layout(&t, None).unwrap(); + (0..6) + .map(|i| form.pages.iter().position(|p| widgets(p).iter().any(|w| w.som == format!("form[0].s[0].f{i}[0]"))).unwrap_or(9)) + .collect::>() + }; + assert_eq!(pages_of(r#"layout="lr-tb""#), [0, 0, 0, 0, 1, 1], "split at the break"); + assert_eq!(pages_of(r#"layout="lr-tb" h="6in""#), [1, 1, 1, 1, 1, 1], "a fixed height moves whole"); +}