Skip to content

Scale the appearance of a form field in a fixed-position block that shrinks to fit #457

Closed

Description

@jakejackson1

An active form field inside a fixed-position block that mPDF scales down to fit its box keeps an appearance laid out for the unscaled field. The text is drawn too large for the widget and is clipped.

$mpdf = new \Mpdf\Mpdf(['useActiveForms' => true]);
$field = '<form><input type="text" name="%s" value="Typed value" size="30" /></form>';
$filler = str_repeat('<p>Filler line that makes the block taller than its box.</p>', 12);
$mpdf->WriteHTML('<p>Page text.</p>');
// 'auto' scales the whole block down to fit the 120 x 40mm box
$mpdf->WriteFixedPosHTML(sprintf($field, 'shrunk') . $filler, 20, 40, 120, 40, 'auto');
$mpdf->WriteFixedPosHTML(sprintf($field, 'normal'), 20, 120, 120, 40, 'auto');

On gravitypdf (f9d3db7), and on #441 (af06334):

Field /Rect size Appearance /BBox Appearance text /DA
normal 91.745 × 16.703 91.745 × 16.703 9.900 Tf at 3.000 4.926 9.9 Tf
shrunk 50.763 × 9.242 50.763 × 9.242 9.900 Tf at 3.000 4.926 5.4777165178989 Tf

In the shrunk field, 9.9pt text sits in a box 9.2pt tall, so its top and its end are clipped. A viewer that redraws the field uses the 5.48pt /DA and draws it correctly, so the field changes size when it's clicked.

Cause. Mpdf::WriteFixedPosHTML() renders the block, then, when $overflow is 'auto' and the block is too big, scales it by $shrink_f. It scales the page content with a transform and each form in HTMLheaderPageForms by hand: x, y, w, h and style['fontsize'] (around src/Mpdf.php:15454). The appearance layout ($form['AP']: font size, line positions, highlights) was computed by Form::appearanceText() when the widget was placed, at the unscaled size, and is not scaled. The appearance stream is then written with the scaled w/h for its /BBox and the unscaled layout inside it. Since #387, every widget has this appearance, so every active field in such a block is affected.

The /DA size is also written unrounded (5.4777165178989), because it's scaled after the value has been formatted.

Expected.

  • The appearance of a field in a scaled block matches the scaled widget. Either scale the layout in $form['AP'] with the rest, or wrap the appearance content in a $shrink_f scale matrix, which also covers the border width and padding.
  • /DA is written at the precision Tf uses elsewhere (3 decimals).
  • Tests: in a block scaled by WriteFixedPosHTML(..., 'auto'), the appearance's Tf size equals the /DA size, and each line's baseline and ascent lie inside the /BBox. Cover a text field, a list box (its highlights) and a button.

CSS position: fixed / absolute blocks are also written through WriteFixedPosHTML(), with their own bounding box. A quick test of an overflow: auto absolute block with too much content did not scale, so I haven't confirmed that CSS can reach this path. The public call above does.

Found by the agent working on #433 (PR #441). It predates that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcreate-upstream-pr

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions