From adab7ef525524f52d089324ab7896d95d403c17b Mon Sep 17 00:00:00 2001 From: tannevaled Date: Fri, 4 Sep 2026 23:02:11 +0200 Subject: [PATCH 1/2] Flow the one root subform that writes no layout, and place 6 more fields on 3 more sheets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pdfium reads an absent `layout` on the outermost subform differently from pdf.js, and the difference shows as a sheet count rather than as a coordinate. pdf.js reads an absent or unrecognised `layout` as "position" wherever it appears (getStringOption, utils.js:70-76), and this package followed it. pdfium's GetLayout (cxfa_contentlayoutprocessor.cpp:365-379) returns the attribute where it parses to one of the seven values, and where it does NOT and the node's parent is the
root it returns Tb. A positioned container is never flowed, so a inside one is never reached — pdfium recurses into one with bUseBreakControl false (line 1163) and the break stage begins by testing it (line 1751) — which is why the whole of the difference is which sheet things land on. FOUR of the corpus's 560 root subforms write no `layout`. Three of them are forms this package put on ONE sheet where pdfium and pdf.js BOTH use two: us-opm__sf39 1 -> 2 sheets, and its 6 unplaced fields are now placed us-opm__sf39a 1 -> 2 sheets us-opm__sf813 1 -> 2 sheets The fourth, us-opm__sf181, has one child and no break, and does not move. Nothing else in the corpus moves: the whole-corpus box dump differs on those three forms and on no other. Against pdfium, per form, boxes on the same sheet: us-opm__sf39 96/104 -> 110/110 (and 6 unplaced -> 0) us-opm__sf39a 24/50 -> 50/50 us-opm__sf813 sheet split 151/16, which is pdfium's 151/16 exactly The half of bRootForceTb this does NOT do is named in [placer.forcedTb]: pdfium also gives such a root's children their WRITTEN x and y instead of the packing cursor. Every child of all four roots writes no x and no y, so nothing in 560 templates separates that from stacking them. The tests that used an absent `layout` as shorthand for a positioned root now write `layout="position"`, which is what they meant and what pdfium reads. Gate: 100% of statements, go vet, gofmt -l empty against Go 1.27.1 via GOTOOLCHAIN, -race, nine cross-compile targets, CGO_ENABLED=0, GOWORK=off. The corpus suite is green, and TestPaginationAgainstPdfjs goes from six disagreements to two. Co-Authored-By: Claude Opus 5 --- layout_test.go | 12 +++++------ paginate.go | 54 +++++++++++++++++++++++++++++++++++++++++++++--- paginate_test.go | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 9 deletions(-) diff --git a/layout_test.go b/layout_test.go index ecbf35f..b820a56 100644 --- a/layout_test.go +++ b/layout_test.go @@ -128,7 +128,7 @@ func TestAFormPlacedByHand(t *testing.T) { func TestAPositionedFormNeedsNoFirstChildRule(t *testing.T) { // The same body under a positioned outermost subform: now every child is // placed at its own coordinates, Body's x=5 y=7 among them. - l := laidOut(t, strings.Replace(worked, `name="form1" layout="tb"`, `name="form1"`, 1)) + l := laidOut(t, strings.Replace(worked, `name="form1" layout="tb"`, `name="form1" layout="position"`, 1)) same(t, "the page", laid(l), []string{ "draw form1.Page1.Stamp 10,20 30x40", // Body: 18+5, 36+7 = 23,43; A: 24,45; Inner: 33,63; B: 36,67 @@ -182,7 +182,7 @@ func TestWhatIsReportedRatherThanPlaced(t *testing.T) { `, []string{"f.P2.Two: its page area is never used: no page of this form is one"}}, {"an origin that is not a place", - ``, []string{"f.A: " + boundByTheRoom("maxH")}}, {"a container anchored by a corner, with no size of its own", - `