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"); +}