Skip to content

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

Merged
jakejackson1 merged 4 commits into
feature/pdfa-2-conformancefrom
fix/432-static-field-css
Sep 23, 2026
Merged

jakejackson1 merged 4 commits into
feature/pdfa-2-conformancefrom
fix/432-static-field-css

Conversation

@jakejackson1

Copy link
Copy Markdown
Member

Fixes #432

What changed

With useActiveForms off, a form field drawn into the page now takes its CSS color, background-color and border. Before this, every field had a near-white fill, black text and a 0.2mm border in whatever stroke colour was already set.

  • Shared groundwork, in the tags. Tag::formFieldStyle() records the field's background-col, border-col, border-width (mm) and border-style into $objattr. It does this for Input (text, password, buttons, checkbox, radio), TextArea and Select (through selectoption, the same way as COLOR), whether or not forms are active.
    • Before, Input and TextArea read BORDER-TOP-COLOR and only inside if ($this->mpdf->useActiveForms). That property is only set when the border-color longhand is written. BorderMerger folds a border shorthand into BORDER-TOP, so border: 0.5mm solid #0000ff never reached the field. formFieldStyle() now reads BORDER-TOP instead.
    • BorderMerger fills the missing parts with 0px none #000000 when only a longhand is given, e.g. border-color on its own. Those filled-in parts are ignored, so the longhand changes only its own part of mPDF's default border. The fill values are now BorderMerger::DEFAULTS, a single constant both classes use.
  • Static drawing (Form::print_ob_*). Text inputs, text areas, selects, buttons, checkboxes and radio buttons now draw with the CSS fill, stroke colour, line width and text colour. Anything the CSS leaves unset keeps today's defaults.
    • The disabled grey (fill and text) and the read-only grey fill still override the CSS.
    • A border of style none or hidden, or of zero width, is not drawn: the field is filled only.
    • Radio buttons: the ring takes the border colour and is filled with the background. The dot stays in the text colour, as before.
    • Checkboxes: the box and its cross take the border colour and width.
  • Active side effect. The active /MK /BC already came from border-col, so it now follows a border colour given in the shorthand too. That is part of An active form field ignores its CSS border and uses the default colour and width #431. The rest of An active form field ignores its CSS border and uses the default colour and width #431 (the /BS width and style, the choice field, and the appearance streams) is in the stacked PR.

Snapshots

Each refresh is its own commit, and each was checked by rasterising with pdftoppm against the old fixture.

  • form-fields-static: only the "Styled" row changed. It now draws dark red text on pale yellow inside a 0.5mm blue border, where before it had black text in a thin black box.
  • form-fields-active, form-fields-pdfa: the styled field's /MK /BC and its appearance border change from the default 0.6 0.6 0.72 to the CSS #0066cc. Nothing else changed apart from the PDF/A document ID.
  • page-break-avoid-forms, page-break-avoid-references: these declare input, select, textarea { border: 0.2mm solid #404040 }. The active text fields, text areas and buttons now draw that grey border instead of the default blue-grey. The select does not yet, because SetFormChoice ignores border-col (fixed in the An active form field ignores its CSS border and uses the default colour and width #431 PR).

Verification

  • tests/Mpdf/StaticFieldStyleTest.php (16 tests) covers:
    • the issue's input: 1.417 w, 0 0 1 RG, 1 1 0.8 rg, and re B followed by the text in 0.753 0 0 rg;
    • every field kind, and a stylesheet rule;
    • the defaults with no CSS;
    • the border-color, border-width and border-style longhands on their own;
    • none, 0, border-width: 0 and hidden, drawn with re f and no stroke;
    • disabled and read-only greys winning over the CSS.
  • composer test: 3761 tests, 5 skipped (pre-existing), no failures.
  • composer test -- --group=snapshot: 88 OK.
  • composer test -- --group=conformance (veraPDF): 26 OK.
  • composer cs: clean. PHPStan 2.2: no errors.
  • php -l under PHP 5.6: clean.

Limits and follow-ups

  • In the static drawing, every border style other than none and hidden is drawn solid. Dashed, dotted, inset and the rest are not imitated.
  • A static button's text used to inherit the surrounding text colour. It now takes the button's CSS color only when one is set.
  • Only the top border is read. Per-side borders on a form field are not supported, as before.
  • Upstream port: this doesn't depend on Give every active form widget its own appearance, and ask the viewer to redraw only text it cannot shape (#348, #59) #387. Tag::formFieldStyle(), BorderMerger::DEFAULTS and the Form::print_ob_* static branches apply to mpdf/mpdf development as they are.

🤖 Generated with Claude Code

jakejackson1 and others added 4 commits September 24, 2026 06:44
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>
…atic field's colours in one place

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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>
@jakejackson1
jakejackson1 force-pushed the fix/432-static-field-css branch from 6185cdf to 2a3430c Compare September 23, 2026 20:47
@jakejackson1
jakejackson1 merged commit 9581528 into feature/pdfa-2-conformance 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
…) (#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>
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
…) (#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>
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

create-upstream-pr enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant