Repository navigation
Give every redrawn form field a new appearance stream - #135
Merged
bobsingor merged 4 commits intoNov 29, 2026
Merged
Conversation
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.
…/form-appearance-new-stream Main brought the inline form font fix (#134), the const read of a drawing rect (#136) and redactions through the active layer (#137). Two conflicts, each where both sides added to the same place. The ledger's own-appearance-generator paragraph keeps both additions. The list of layer-mode writers keeps both sides' tests, and EPDFFormEmbedderTest.AFieldWithoutWidgetsGetsNoDrawing, new on main, leaves 8 objects in a layer where main lists 7: one more for the new stream of its redraw.
A second review of pull request 135 found two more things a redraw into the old stream had kept and a new stream lost. /N, /R and /D are each one stream or a dictionary of states, whatever the others are. FollowReplacedStream handled /R and /D only in the shape /N had, so a text field's /R << /Shown ... >> naming its one normal stream went on naming the old one. FollowReplacedStreams now goes through every reference under the entry, the entry itself or a state of it, and makes each that named a replaced stream name the one standing for it. Where two states were one stream, a state follows its own. A stream's resources may hold default colour spaces, which its device colours are read in. The new stream held only its fonts, so a field drawn through a calibrated /DefaultRGB changed colour in a reader that goes by it. CarryHowADrawingShows gives the new stream what the old one says of any drawing in it: /OC as before, /DefaultGray, /DefaultRGB and /DefaultCMYK, and /Group, which the review did not name but is of the same kind: it says how the stream is composited. The rest of the old dictionary and resources is about the old drawing and is left, so what it named is no longer kept in the file. Test: EPDFWidgetDrawingEmbedderTest.ARedrawKeepsHowItsAppearanceShows, the test over every kind under a new name. Every stream now has a group, default colour spaces, and a colour space and a picture of its own that must not come along. It adds a text field with states under /R and /D, a check box with one stream under /D, and one whose two states were one stream. Without the change it fails for every kind and for the first two of those.
bobsingor
added a commit
to embedpdf/embed-pdf-viewer
that referenced
this pull request
Nov 30, 2026
The release has the runtime changes merged since 7f399f838: - A redrawn form field gets a new appearance stream, where a text field, a dropdown and a list box were drawn into the one they had (embedpdf/runtime#135). An undo puts back the stream the widget named, so it brings the drawing back. The undo round trips this branch adds failed on the old pin and pass on both engines on this one. - Asking where an annotation without a stored appearance draws reads its dictionary and no longer copies it into the document's changes (embedpdf/runtime#136). - A font the form holds inline is made an object of its own before an appearance names it (embedpdf/runtime#134), and a redaction is applied at the place its mark has in a layer (embedpdf/runtime#137). - The upstream sync to 31e80351b (Nov 25 2026, embedpdf/runtime#138). The bindings generated from the release's headers don't change. runtime-src moves to the pin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 keysAP MK). An import puts an object back only where the layer holds no version of its number (InstallObjects, guarded byEPDFCaptureEmbedderTest.ImportNeverReplacesAVersionTheLayerHolds). So a widget gets the appearance it had back only when the write left the stream it named as it read.GenerateFormAPToTargetdrew 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/Vand 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:
/AP, that two widgets name was written into for both.Change
GenerateFormAPToTargetmakes a new stream for every kind and names it in an/APof 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.NameNormalAppearance, names the new appearance for every form drawer (text, combo box, list box, both push button drawers, the box, check box, radio button):/OC), its transparency group (/Group) and the default colour spaces in its resources (/DefaultGray,/DefaultRGB,/DefaultCMYK). For a check box or a radio button each state's new stream takes them from that state's old one./Ror/Dthat named a replaced stream names the new one. Each of/N,/Rand/Dis one stream or a dictionary of states, whatever the others are, so every reference under the entry is followed: the entry itself or a state of it. Where two states were one stream, a state follows its own new stream. A rollover or pressed appearance made apart stays as it is. A dictionary of states that is an indirect object is copied onto the widget first, as/APis./Type,/Subtype,/Matrix,/BBoxand/Resourceswith the fonts) and the three things above. What is drawn does not change.own-appearance-generatorrule and the comment ofEPDFAnnot_GenerateFormFieldAP()state the rule for every kind.The second point is the second and the last commit, after two reviews: a redraw into the old stream had kept all of it for a text field, a combo box and a list box, and the first commit lost it. The kinds that got new streams before (push button, box, check box, radio button) had lost it already, so for those it is a change from the released runtime.
/Groupis in neither review. It is of the same kind as the other two, since it says how the stream is composited, so it is carried by the same rule.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.EPDFCaptureEmbedderTest.RedrawnFieldComesBackWithItsSameAppearances: a rollover appearance that is the normal one follows the redraw to the new stream, and the import brings both back.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/APand one stream each get an/APand a stream of their own, and the shared two stay as they were.EPDFWidgetDrawingEmbedderTest.ARedrawKeepsHowItsAppearanceShows: a widget of every kind (text, combo box, list box, push button with a caption and without, signature box, check box, radio button) whose appearance is in a layer that is off, has a transparency group and default colour spaces, and whose/Rand/Dare its/N. After a redraw each new stream has the layer, the group and the default colour spaces, and neither the colour space nor the picture that the old drawing alone named./Rand/Dname the new stream, per state for the two with states. Three more shapes: a text field with one stream under/Nand dictionaries of states under/Rand/D, a check box whose/Dis the stream of one of its/Nstates, and a check box whose two states were one stream. A rollover appearance made apart stays, and so does a dictionary of states that is an object of its own.Checked
On the branch at
a7de2feed9, which has main (0585b319eb) merged in:check-fork-tags.py --strict,check-c-api.py(604 functions),check-globals.pyon a macOS library built from this branch.EPDFSlicedLoadEmbedderTest.SlicesKeepToTheirBudget, which measures the wall-clock time of a page load's steps and touches no form. It passed in both systems' suite runs above. It failed in the first Linux layer-mode run, which was run again (no error, the test failing in that run's plain half instead), and in the macOS run that fed the saved-file checker. Alone it passed 7 times of 8 on Linux and 1 of 3 on the loaded Mac./OCfor a layer that is off: the released runtime keeps the entry; the first commit lost it and Ghostscript drew the new value; now the new stream holds it and Ghostscript draws nothing./N,/Rand/Dare one stream: after a fill all three name the new stream and draw the new value, where the first commit left/Rand/Don the old one./OCand/Dfollows them. The released runtime loses both./Nand/R << /Shown >>,/D << /Shown >>naming it: after a fill all three name the new stream and draw the new value, where the second commit left the two states on the old one./DefaultRGBthat makes it blue: the released runtime keeps the entry; the first two commits lost it and Ghostscript drew the field red; now the new stream holds it and Ghostscript draws blue./BBox /Group /Matrix /Resources /Subtype /Type, its resources/ColorSpace /Font, its colour spaces the three defaults. The old stream's picture, pattern and metadata are not in the file saved in full, where the released runtime, which wrote into the old stream, kept all of them./Vand stream agree.Left
fix/undo-restores-field-appearancethere and fail until the pin.own-appearance-generatorparagraph, and its new tests' counts in the writers list need taking again.check-globals.py, and Acrobat, on none of these cases and not on a file filled in after a signature. The engine's signature tests pass on this runtime./OCon an appearance stream nor a default colour space for device colours, with or without this change, so the engine's pictures of those two cases are the same throughout. What this change keeps is what the saved file says, for a reader that goes by it.SetDetachedNormalAppearanceinepdf_annot.cpp, a stamp's or a mark's picture set as the appearance) names its new stream without carrying any of this or following/Rand/D.