Skip to content

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

Merged
jakejackson1 merged 4 commits into
fix/432-static-field-cssfrom
fix/431-active-field-border
Sep 23, 2026
Merged

jakejackson1 merged 4 commits into
fix/432-static-field-cssfrom
fix/431-active-field-border

Conversation

@jakejackson1

Copy link
Copy Markdown
Member

Fixes #431

Stacked on #442 (#432). That PR has the shared groundwork: the form tags record the field's CSS border, read from the BORDER-TOP shorthand, whether or not forms are active. It also already made /MK /BC follow a shorthand border colour. This PR adds the border width and style, and brings the select field in.

What changed

  • /BS /W now comes from the CSS border width in points. /BS /S comes from its style:
    • solid → /S
    • dashed → /D /D [3]
    • dotted → /D /D [1]
    • inset → /I
    • outset → /B
    • double, groove and ridge → /S, since PDF has no equivalent.
  • border: none or border-style: hidden gives /W 0, and /MK leaves out /BC, because a viewer that redraws the field draws a border wherever /BC is present. The same applies to text and choice fields left at SetFormBorderWidth('0').
  • Give every active form widget its own appearance, and ask the viewer to redraw only text it cannot shape (#348, #59) #387's appearance streams now draw the same border: its colour, its width (with the text inset by it, as before), and the dash pattern for a dashed or dotted style. Colours still go through appearanceColor(), so they follow the output intent. /MK is also CMYK when the document is restricted to CMYK.
  • Fields covered: text inputs, textareas, selects (combo and list), and submit, reset and JS buttons. SetFormChoice also takes the select's CSS border-color and background-color now; before, it ignored them.
  • Implementation:
    • Form::activeBorder($objattr) turns the recorded CSS into ['W' => …, 'S' => …].
    • SetFormText, SetFormChoice, SetFormButton and the reset, submit and JS button wrappers take it as a new trailing optional $border array. When the array leaves W or S out, the existing form_border_* or form_button_border_* default is used for it.
    • SetFormChoice also gains the $background_col and $border_col parameters the others already had.

Snapshots

Refreshed in their own commit and checked by rasterising with pdftoppm:

  • form-fields-active and form-fields-pdfa: the "Styled" field's border goes from 1pt to 0.5mm (1.417pt) in both /BS and the appearance. Otherwise only the PDF/A document ID changes.
  • page-break-avoid-forms and page-break-avoid-references: these set border: 0.2mm solid #404040 on fields. The active fields now draw that thinner 0.567pt border, and the select picks up the grey border colour too.

Verification

  • tests/Mpdf/ActiveFieldBorderTest.php has 18 tests:
    • the issue's input: /BS << /W 1.417 /S /S >>, /MK <</BC [ 0 0 1 ] /BG [ 1 1 0.8 ], and an appearance stroking 0 0 1 RG 1.417 w;
    • each field kind;
    • the defaults;
    • every style mapping, including the dash in the appearance;
    • none and hidden: /W 0, no /BC, no stroke;
    • the longhands on their own;
    • CMYK colours under PDF/A with restrictColorSpace 3.
  • composer test: 3779 tests, 5 skipped (these were already skipped before this change), no failures.
  • composer test -- --group=snapshot: 88 OK.
  • composer test -- --group=conformance (veraPDF): 26 OK.
  • A PDF/A-2B document with a dashed text field, a borderless text field, an inset select with a background, a dotted submit button and a 2pt solid textarea passes veraPDF 2b.
  • composer cs is clean. PHPStan 2.2 reports no errors. php -l under PHP 5.6 is clean.

Limits and follow-ups

🤖 Generated with Claude Code

jakejackson1 and others added 4 commits September 24, 2026 06:48
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>
…n the field kinds

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…lect'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>
@jakejackson1
jakejackson1 force-pushed the fix/431-active-field-border branch from 29c6463 to d6513a6 Compare September 23, 2026 20:51
@jakejackson1
jakejackson1 merged commit c675d3f into fix/432-static-field-css Sep 23, 2026
29 checks passed
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
#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.
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
#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.
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
#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.
@jakejackson1
jakejackson1 deleted the fix/431-active-field-border 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 create-upstream-pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant