Skip to content

Show a list box's rows whole in its appearance (#426) - #444

Merged
jakejackson1 merged 1 commit into
gravitypdffrom
fix/426-choice-appearances
Sep 23, 2026
Merged

jakejackson1 merged 1 commit into
gravitypdffrom
fix/426-choice-appearances

Conversation

@jakejackson1

@jakejackson1 jakejackson1 commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Rebased onto gravitypdf after #470 as one commit, since feature/pdfa-2-conformance had already been merged by #330. The branch's earlier commits added the combo box arrow and then removed it, so only the list box change is left. print_ob_select() passes SetFormChoice() the rows that #446 now records on the select, guarded for callers that build their own attributes (#441's FormFieldShrinkTest). form-fields-active and form-fields-pdfa were refreshed again: the only difference from gravitypdf is that the list box and multiple select show their rows whole ("Fourth" was cut off before).

Fixes #426

Fixes the list box rows in the appearance streams #387 draws for choice fields. Since #387, every viewer draws a Latin-only form from these streams.

#426 raised two problems. This fixes the first, the clipped list box rows. It deliberately does not do the second, a drop-down arrow in the combo box's appearance: see below.

What changed

List box rows are shown whole. Tag\Select makes a list box size × the font size tall, plus padding. That is shorter than size rows at the font's own line height (ascent − descent, about 1.16 em in DejaVu). The old layout used the natural line height below a 2pt top padding, so the last row ran past the clip at the border and a one-row box could show the top of the next option.

  • The rows now share the height inside the border equally, and the highlight uses the same row height.
  • Where a row is shorter than the font's line height, the appearance's font shrinks to fit, so each row's glyphs stay inside the row. This is about 2% for size="3" at the default size and about 10% at size="10".
  • Only size rows are drawn. Scrolling to the first selected option works as before.
  • Tag\Select now stores the row count it used for the height as $objattr['rows']. print_ob_select() passes it through a new optional $rows argument of SetFormChoice(), so the row split cannot drift from the box height. This doesn't change the layout.

A combo box's appearance has no drop-down arrow. An earlier revision of this PR drew one. Acrobat draws its own button over a combo box, and pdf.js lays an HTML <select> over it, so the arrow showed twice in exactly the viewers where the field is used. Acrobat's own combo box appearances carry no arrow either. So a printed or flattened combo box shows no arrow, as one Acrobat made would, which is the trade-off #426's second point raised. The appearance is unchanged from #387 apart from the rows fix above, and a test now holds every choice appearance to having no arrow, with its text clipped at the full inner width.

Snapshots

  • form-fields-active and form-fields-pdfa: the size="3" and size="4" list boxes show their last row ("Third", "Fourth") whole and slightly more tightly spaced. Nothing else moves.
  • page-break-avoid-forms: unchanged from the base branch in its pixels.

Each refresh was checked by rasterising old against new. The last refresh, which removed the arrow, differs from the fixture before it only in the button's pixels.

Verification

  • composer test: 3886 tests OK. The 5 skips are the checks that regenerate the Unicode, OpenType and emoji tables, unrelated to this change.
  • composer test -- --group=snapshot: 90 OK. --group=conformance (veraPDF): 29 OK.
  • composer test -- --group=conformance (veraPDF): 26 OK, including the active-form cases.
  • composer cs clean; php -l under PHP 5.6 clean. PHPStan 2.2.15 reports only the unmatched Svg.php baseline entry that Drop the isset() on a foreach variable that PHPStan 2.2.15 no longer reports #451 fixes on gravitypdf.
  • FormAppearanceTest:
    • testListBoxShowsItsRowsWhole: 1, 3 and 6 rows, in embedded and core fonts, at 16pt. Exactly size lines are drawn, the clip height is size rows, and each line's ascent-to-descent box lies inside its own row. It fails on the base branch for every case: the one-row box drew a second line with a negative baseline.
    • testAChoiceFieldAppearanceHasNoDropDownArrow: a combo box and one- and two-row list boxes draw no triangle and clip at the full inner width. It fails for the combo box on the previous revision.
  • Rendered 1/3/4/10-row list boxes and a combo box at 16pt, before and after, in Ghostscript. With the arrow in the appearance, Acrobat Reader showed two arrows on the combo box. With it removed, Foxit shows one.

Limits / follow-ups

🤖 Generated with Claude Code

The appearance of an active list box split the height inside its border
between the rows by the font's line height, so the last row was cut off.
It now takes its rows from the select tag, gives each an equal share of that
height, shrinks the font to keep each row whole, and draws only that many
rows, starting at the first selection when it would fall below the last.
A highlight fills its row.

Rebased onto gravitypdf as one commit: the branch's six commits had added a
combo box drop-down arrow and then taken it out again, as viewers draw their
own, so only the list box change remains.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jakejackson1
jakejackson1 force-pushed the fix/426-choice-appearances branch from 3fddda3 to 38764f6 Compare September 23, 2026 22:12
@jakejackson1
jakejackson1 changed the base branch from feature/pdfa-2-conformance to gravitypdf September 23, 2026 22:12
@jakejackson1
jakejackson1 merged commit e74da2b into gravitypdf Sep 23, 2026
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
#444's list box test looked for the Tm each appearance line was placed with.
The lines now go through Mpdf::Text(), which places them with Td.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
…s drawn (#408) (#448)

* Shape and order the text of a form widget's appearance as page text is drawn

Appearance text was written character by character, so Arabic and Indic
values showed unjoined glyphs and right-to-left values ran in logical
order. Each line now goes through applyOTL() and magic_reverse_dir(), is
measured as shaped, and is written with the operators Cell() uses:
applyGPOSpdf() where OTL positioned glyphs, a plain string otherwise.

With the appearances right, no form asks the viewer to redraw them, so
/NeedAppearances, the /ZaDb font it needed for checkboxes (#59) and
Otl::hasComplexScript() go.

A text area with an auto font size is drawn at the largest size up to
12pt at which its wrapped text fits the field's height.

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

* Write appearance text through Mpdf::Text(), and measure each word of a field once

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

* Say why appearance text sets the font size and keeps word widths

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

* Check that an active field's Arabic value is fitted by its shaped width, and trimmed by shaping what fits again

fitLine() measures appearance text through emWidth(), which now shapes it,
so a shaped value is sized by the width it is drawn at and a trimmed one is
the shaped start of the value, not a cut of the whole shaped line.

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

* Draw an appearance line with the shaping it was measured with, instead of shaping it again

A fitted line was already shaped to be measured, and the draw loop shaped it
again. It now takes the shaped text, its OTL data and its width from the same
per-field cache emWidth() fills. Say why the appearance sets its font in an
empty text object.

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

* Say plainly how the shaped fitting test's value is measured

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

* Refresh the form snapshots whose appearance text is shaped and written by Mpdf::Text()

form-fields-active, form-fields-pdfa, page-break-avoid-references and
page-break-avoid-forms. Against the #433 fixtures, the Arabic value is shaped
and right to left in both renderers, poppler draws form-fields-active from its
appearances now that /NeedAppearances is gone, and "A field" takes the fi
ligature on pages 2 and 3 of page-break-avoid-references. page-break-avoid-forms
changes in bytes only. The maxlength field's fitted value is unchanged.

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

* Read a list box's rows from the operators Mpdf::Text() writes

#444's list box test looked for the Tm each appearance line was placed with.
The lines now go through Mpdf::Text(), which places them with Td.

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

* Add a snapshot of active fields showing shaped text beside the same text on the page

Each row puts a value written on the page next to an active field showing it
in the same font: Arabic, Arabic with vowel marks, Hebrew, a value mixing
directions, Kannada and Thai, a value shrunk to fit, a wrapped and an
auto-sized text area, a combo box, a list box and a button. Before #408 the
fields drew Arabic unjoined and every right-to-left value backwards, broke up
Kannada, misplaced Thai marks, and left an auto-sized text area at 12pt.

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
jakejackson1 deleted the fix/426-choice-appearances 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.

Choice field appearances clip the last list row and draw a combo box without an arrow

1 participant