Skip to content

Give every redrawn form field a new appearance stream - #135

Open
bobsingor wants to merge 2 commits into
embedpdf/mainfrom
embedpdf/fix/form-appearance-new-stream
Open

bobsingor wants to merge 2 commits into
embedpdf/mainfrom
embedpdf/fix/form-appearance-new-stream

Conversation

@bobsingor

Copy link
Copy Markdown
Contributor

Cause

The engine undoes a form write by putting the field's and its widgets' dictionaries back with EPDFDoc_ImportDictRaw(), from a capture taken before the write (EPDFDoc_ExportDictRawToOwnedBuffer() with the deep keys AP MK). An import puts an object back only where the layer holds no version of its number (InstallObjects, guarded by EPDFCaptureEmbedderTest.ImportNeverReplacesAVersionTheLayerHolds). So a widget gets the appearance it had back only when the write left the stream it named as it read.

GenerateFormAPToTarget drew a text field, a combo box and a list box into the stream the widget already named. A push button, a check box, a radio button and a box got a new stream on every redraw.

So after a value written over an appearance, a reset, an appearance text (EPDFForm_SetFieldAppearanceText()) or a restyle, the import put /V and the widget's keys back, and the widget still named the same stream, which drew what the undone write had drawn. The page showed the undone value, and a saved file held /V (hello) under a stream that draws (hello world). One fill and its undo is enough. It has been so since captures exist.

Two more things followed from writing in place:

  • A stream the file holds was copied into the layer and written there. A capture never holds the file's originals, so nothing could bring it back.
  • A stream, or an indirect /AP, that two widgets name was written into for both.

Change

  • GenerateFormAPToTarget makes a new stream for every kind and names it in an /AP of the widget's own (OwnAppearanceDict). The stream the widget had is not opened for writing, so nothing of it is copied into a layer, and a save writes only what the document still reaches.
  • The new stream's dictionary is what a first drawing's was: /Type, /Subtype, /Matrix, /BBox and /Resources with the fonts. Other keys the old stream's dictionary held are not carried over. What is drawn does not change.
  • The ledger's own-appearance-generator rule and the comment of EPDFAnnot_GenerateFormFieldAP() state the rule for every kind.

Tests

  • EPDFCaptureEmbedderTest.RedrawnFieldComesBackWithItsAppearance: a field filled in twice, with a capture before the second fill. The second fill names a new stream and leaves the first as it read; the import brings the widget back naming the first, with its bytes, also after a save and reopen dropped it.
  • EPDFCaptureEmbedderTest.RedrawnFieldLeavesTheFilesAppearanceAlone: a widget that names a stream of the file, which a square names too. After a fill the layer holds no version of it, the square still names it, and the import brings the widget back naming it.
  • EPDFFormEmbedderTest.RedrawIsANewStreamEveryTime: a text field, a combo box and a list box each get another stream on a second redraw, and the first still draws what it drew.
  • EPDFFormEmbedderTest.RedrawLeavesASharedAppearanceAlone: two widgets naming one indirect /AP and one stream each get an /AP and a stream of their own, and the shared two stay as they were.
  • The two form tests are listed as layer-mode writers. 21 tests that redraw a text or choice field leave one to six more objects in a layer, one for each redraw; their counts in the list are updated.

Checked

  • Without the change all four tests fail.
  • macOS: unit 1412 passed. Embedder 1888 passed and 12 failed, the 12 golden failures an unchanged build of the base has, by name.
  • Linux x64, in the release image: unit 1419 passed, embedder 1902 passed, none failed.
  • The whole suite in layer mode on Linux: no error, 592 writers, each with the count the list gives. On macOS the whole suite reported only the two new form tests, as writers the list did not have yet; with the list they pass.
  • Pixel runner on macOS: 147 pass, 51 fail and 2 surprises of 224, the same names as on the base build.
  • The saved-file checker over the macOS embedder run: 49 saved PDFs pass.
  • check-fork-tags.py --strict, check-c-api.py (604 functions), check-globals.py on the macOS library.
  • WebAssembly and a macOS library built from this branch, in the engine at the current pin:
    • Five undo round trips over a widget that holds a drawing (a second value, an appearance text, a reset, a restyle, a combo box's second choice) fail on the released runtime and pass on this one, in the local engine and through the server.
    • The local engine's suite passes (2278 tests), and the cloud engine's, which runs through the server (1394).
    • A text field's drawing after a fill and after a restyle, and a combo box's after a restyle, are the same pixels as with the released runtime.
    • In a browser: fill, fill, undo, undo, redo each draw the right value, and the saved file's /V and stream agree.

Left

An undo of a form write puts the field's and its widgets' dictionaries
back from a capture taken before the write. An import never replaces an
object the layer holds a version of, since that version may be newer. So
a widget gets the appearance it had back only when the write left that
stream as it read.

A text field, a combo box and a list box were drawn into the stream the
widget already named. After a second value, a reset, a shown text or a
restyle, the undo put /V and the widget's keys back, and the widget still
named the same stream, which drew what the write had drawn: the page and
a saved file showed the undone value. The stream was also written into
when the file held it, or when another widget named it too.

GenerateFormAPToTarget now makes a new stream for every kind, as it did
for a push button and as the check box, radio button and box drawers do,
under an /AP of the widget's own (OwnAppearanceDict). The old stream is
not opened for writing, so nothing of it is copied into a layer, and a
save writes only what the document still reaches.

Tests: EPDFCaptureEmbedderTest.RedrawnFieldComesBackWithItsAppearance and
RedrawnFieldLeavesTheFilesAppearanceAlone,
EPDFFormEmbedderTest.RedrawIsANewStreamEveryTime and
RedrawLeavesASharedAppearanceAlone. All four fail without the change. The
two form tests are listed as layer-mode writers, and 21 tests that redraw
a text or choice field leave one to six more objects in a layer, one for
each redraw.
A review of pull request 135 found two things a new stream lost, which a
redraw into the old stream had kept for a text field, a combo box and a
list box. The kinds that got new streams before had lost them already.

A stream may say which layer it shows in (/OC). The new stream said
nothing, so a field whose appearance is in a layer that is off showed its
value after a fill, in a reader that goes by the entry.

A widget's rollover and pressed appearances (/R, /D) may be its normal
one. They went on naming the old stream, with the old value.

NameNormalAppearance now names the new appearance for every drawer. A new
stream takes the /OC of the stream it replaces, the one of its state for
a check box or a radio button. An /R or a /D that named the replaced
stream, for the widget or for a state, names the new one, and one made
apart stays as it is. A dictionary of states that is an indirect object
is copied onto the widget first, as /AP is: another widget may name it.

A capture taken before the redraw still brings everything back, since it
puts the widget's /AP back whole.

Tests:
EPDFWidgetDrawingEmbedderTest.ARedrawKeepsTheLayerAndTheSameAppearances,
over a text field, a combo box, a list box, a push button with a caption
and one without, a signature box, a check box and a radio button, and
EPDFCaptureEmbedderTest.RedrawnFieldComesBackWithItsSameAppearances. Both
fail without the change, the first for every kind. The first is listed as
a layer-mode writer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant