Skip to content

Bring the form field PRs merged into feature/pdfa-2-conformance after #330 into gravitypdf - #470

Merged
jakejackson1 merged 5 commits into
gravitypdffrom
forward/pdfa-2-form-fields
Sep 23, 2026
Merged

jakejackson1 merged 5 commits into
gravitypdffrom
forward/pdfa-2-form-fields

Conversation

@jakejackson1

@jakejackson1 jakejackson1 commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #431
Fixes #432
Fixes #433
Fixes #443

feature/pdfa-2-conformance was squash-merged into gravitypdf by #330 (f9d3db7, 23 Sep). Its contents are identical to the branch at 656219b. Four PRs were then merged into that branch, so their changes never reached gravitypdf. This PR cherry-picks them, in the order they were merged, and adds one fix that the four needed together.

Commit From Change
476e5a4 #441 (3a13fcd) Shrink a form field's text to fit its field instead of cutting it off (#433)
761a6be #442 (9581528) Draw a static form field in its CSS colour, background and border (#432)
79a5af6 #469 (8148660), the restore of #445 Give an active form field the width and style of its CSS border (#431)
c10ec3e #447 (543906b) Write push buttons that share a name as one field, with each widget as a kid (#443)
736154f new Keep an image button's icon under the button's own form number

Conflicts with gravitypdf

Both were with #438 (#147), which gives an unnamed button a generated name, and which reached gravitypdf after the feature branch was merged.

#442 and #447 applied cleanly. After #446 merged, the branch was rebased onto it. The only conflict was the form-fields-static fixture, which #446 and #441/#442 both change; it was regenerated at each commit. It now shows #446's list boxes, the "Max length" value shrunk to fit (#441) and the "Styled" field in its CSS colour, background and border (#442), and nothing else moved. Apart from #438's lines, src/Form.php after the four picks is identical to feature/pdfa-2-conformance.

The fix in 736154f

feature/pdfa-2-conformance has been broken since #447 merged: AnnotationObjectNumbersTest (4 errors), FormFieldShrinkTest::testIconButtonKeepsTheFieldsSize, SharedButtonNameTest::testImageButtonsThatShareANameKeepTheirIcons and the form-fields-active and form-fields-pdfa snapshots all fail there. #447 merged three minutes after #469, and each PR's CI ran without the other.

The icon is now kept under $this->formCount + 1, the number SetFormButton() is about to give the button, which is the same idea as #438's unnamedButtonName(). SetFormButton() looks for it under $this->formCount. The failing tests listed above cover it; no new test was needed.

Verification

  • composer test: 3879 tests, 5 skipped (these were skipped before this change too), no failures.
  • composer test -- --group=snapshot: 90 OK.
  • composer test -- --group=conformance (veraPDF): 29 OK.
  • composer cs is clean. PHPStan 2.2 reports no errors. php -l under PHP 5.6 is clean.

After this merges

🤖 Generated with Claude Code

@jakejackson1 jakejackson1 added the bug Something isn't working label Sep 23, 2026
jakejackson1 and others added 5 commits September 24, 2026 07:55
…#433) (#441)

* Shrink a form field's text to fit its field instead of cutting it off (#433)

A text input's value, a combo box's choice and a push button's caption that
are too wide for the field are drawn in a smaller font, both into the page and
in an active field's appearance. The size scales with the overflow, rounded
down to 0.001pt, and goes no lower than half the field's size or 6pt. Past that
minimum the text is trimmed to whole characters, found by halving. One rule,
fitLine(), serves every case.

An active text field or combo box that shrinks is written with /DA 0 Tf so the
viewer sizes it too. A push button's /DA names the size its appearance was
drawn at. /V, /DV, /Opt and /CA keep the whole text.

The static button now shapes its caption through shapeText(), and a static
text input measures the value as Cell() draws it, padding shrunk with a shrunk
table included.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Drop the isset() on a foreach variable that PHPStan 2.2.15 no longer reports (#451)

The baseline ignored "Variable $c in isset() always exists" in Svg.php. PHPStan 2.2.15 stopped
reporting it, so the unmatched ignore failed static analysis on gravitypdf and every branch cut
from it. $c is always set inside its foreach, so the check goes and the ignore with it, which
passes under 2.2.14 and 2.2.15 alike.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…) (#442)

* Draw a static form field in its CSS colour, background and border (#432)

A field drawn into the page, with active forms off, always had a near-white
fill, black text and a 0.2mm border in the colour already set. The form tags
now record the field's background and border, read from the BORDER-TOP
shorthand the cascade folds the border into, whether or not forms are active,
and Form draws text inputs, text areas, selects, buttons, checkboxes and radio
buttons with them, keeping the defaults for what the CSS leaves unset. The
disabled and read-only greys still win, and a border of style none or no width
is not drawn.

An active field's /MK /BC now also follows a border colour given in the border
shorthand, which only the border-color longhand reached before.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Share BorderMerger's border defaults with the form tags, and set a static field's colours in one place

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Say what the static field style helpers do more plainly

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Refresh the form snapshots for a field's CSS colours and border

form-fields-static draws its styled field in dark red on pale yellow inside a blue border, and
form-fields-active and form-fields-pdfa take that blue as the widget's border colour. The
page-break-avoid fixtures draw their fields' grey CSS border. Rasterised against the base branch,
nothing else changes; against this branch before its rebase onto #441, only the maxlength field
differs, which #441 draws whole in a smaller font.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
#445) (#469)

* Give an active form field the width and style of its CSS border (#431)

An active text field, text area, select or button always had a 1pt solid
border in /BS, whatever its CSS said. The border width, in points, and style
the form tags record now reach /BS and the appearance: solid, dashed, dotted,
inset and outset become /S, /D (dashed in the appearance too), /I and /B, and
a border of style none has no width and no /BC, which a viewer would draw
regardless. A select also takes its CSS border and background colours, which
it ignored before.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Share the active field colour fallback and the no-border rules between the field kinds

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Say what the active border helpers do more plainly

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Refresh the active form snapshots for the CSS border width and the select's border colour

form-fields-active and form-fields-pdfa write the styled field's 0.5mm border in /BS and draw it
in its appearance. page-break-avoid-forms and page-break-avoid-references draw their fields'
0.2mm CSS border, thinner than the 1pt default, and their select takes its grey colour too.
Rasterised against #432's fixtures only those borders change; against this branch before its
rebase onto #441, only the maxlength field differs, which #441 draws whole in a smaller font.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Cherry-picked from c675d3f. PR #445 was merged into fix/432-static-field-css after #442 had
already merged that branch into feature/pdfa-2-conformance, so it never reached this branch.
… a kid (#447)

* Write push buttons that share a name as one field with each widget as a kid

Same-named submit, reset, script and image buttons were written as separate
fields with the same /T, and their script and icon were looked up by name, so
the second button's script replaced the first's and was then used up. Each
group is now a parent field (/FT /Btn, push-button flag, /T, /Kids) listed in
/AcroForm /Fields but in no page's /Annots, and its widgets keep their own
action, caption, icon and appearance under a /Parent. Scripts and icons are
keyed by the button's form number.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Read the reference lists in the shared button name tests with one helper, and write the push-button flag as the widgets do

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Say what a push button is where the shared button name code asks

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
#441 moved SetJSButton()'s SetFormButton() call below the icon, so that the
field knows it shows one, and #447 keyed the icon by $this->formCount, which
is the button's number only once SetFormButton() has counted it. Merged
together, each icon went to the form before it: the widget lost its icon, the
object count reserved one that was never written, and SetFormButton() still
looked the icon up by name. The icon is now kept under the number the button
is about to get, and SetFormButton() looks for it there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jakejackson1
jakejackson1 force-pushed the forward/pdfa-2-form-fields branch from 9c01d2d to 736154f Compare September 23, 2026 21:58
@jakejackson1
jakejackson1 merged commit 21e4759 into gravitypdf Sep 23, 2026
29 checks passed
@jakejackson1
jakejackson1 deleted the forward/pdfa-2-form-fields branch September 30, 2026 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

1 participant