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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CBVyQEwtmEw3mS1MoAiwrK
This commit is contained in:
mtlcl410
2026-10-28 15:38:49 +08:00
co-authored by Claude Opus 5.5
parent be00c1300e
commit c09ce0b204
2 changed files with 31 additions and 1 deletions
+6 -1
View File
@@ -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();
+25
View File
@@ -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#"<field name="f{i}" w="7in" h="1in"/>"#)).collect();
format!(
r#"<template xmlns="http://www.xfa.org/schema/xfa-template/3.3/"><subform name="form" layout="tb">
<pageSet><pageArea name="p"><contentArea x="0.5in" y="0.5in" w="7.5in" h="10in"/><medium short="8.5in" long="11in"/></pageArea></pageSet>
<field name="tall" w="7in" h="6in"/><subform name="s" w="7.5in" {attrs}>{rows}</subform>
</subform></template>"#
)
};
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::<Vec<_>>()
};
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");
}