Skip to content

Show one drawing as a stamp, a mark in a widget and a push button's icon - #129

Open
bobsingor wants to merge 3 commits into
embedpdf/mainfrom
embedpdf/feature/button-icon
Open

bobsingor wants to merge 3 commits into
embedpdf/mainfrom
embedpdf/feature/button-icon

Conversation

@bobsingor

@bobsingor bobsingor commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Cause

A picture is the same thing wherever it shows: a form the document holds once, with a small
placement around it. Only stamps worked that way. A mark in a signature field was imported again
for every widget: the same 17 KB picture in ten fields saved as 504 KB, where ten stamps of it
save as 56 KB. And the fork could not write a push button's icon, which is what a field that
holds a picture is in a file (/MK /TP 1, the picture in /MK /I, an /AP /N that draws it; an
image field as Acrobat writes one). Its generator drew every push button as its caption, so a
button another app made with a picture lost it from the appearance when it was drawn again.

Change

Three functions are renamed, with no shim. A drawing is no longer a stamp's alone.
Arguments and results are unchanged.

Was Is
EPDFAnnot_SetStampDrawing(annot, drawing, fit) EPDFAnnot_SetDrawing(annot, drawing, fit)
EPDFAnnot_GetStampDrawing(annot) EPDFAnnot_GetDrawing(annot)
EPDFDoc_GetStampDrawings(document, buffer, buflen) EPDFDoc_GetDrawings(document, buffer, buflen)

Commit 1: drawings serve widgets, and an icon-only button is drawn.

  • EPDFAnnot_SetDrawing places a drawing in a widget as it does on a stamp, fitted and
    turned exactly as EPDFAnnot_UpdateAppearanceToRect fits a widget's mark.
    EPDFAnnot_GetDrawing reads it back, a mark placed the old way included. Both take a stamp
    and a widget, and no other subtype.
  • Icons by drawing: EPDFAnnot_SetMKIcon, EPDFAnnot_GetMKIcon, EPDFAnnot_ClearMKIcon and
    EPDFAnnot_HasMKIcon for /MK /I, /RI and /IX.
  • One list: EPDFDoc_GetDrawings also lists the drawings widgets' marks place and the forms
    /MK names as icons. An appearance whose resources name no XObject is not decoded, and
    listing writes nothing.
  • A placement only reads the drawing, and EPDFAnnot_SetDrawing checks before it opens the
    annotation for writing. A drawing an earlier revision holds can be placed after a signature.
  • The generator draws an icon-only push button from /MK /I (GenerateIconButtonAP): inside
    the border, fitted by /MK /IF or by the PDF's defaults, in the frame /MK /R gives, by the
    icon's /BBox through its /Matrix. No caption and no /DA are needed.
  • Nothing is deleted. A save writes only what a root still reaches.

Commit 2: a caption and an icon together (/MK /TP 2 to 6).

  • Both are drawn, each in its part of the button, shared by the rule of PDFium's form filler
    (GetPushButtonAppStream): a strip as high as the caption's line below or above the icon, or
    as wide as its text beside it, and the icon in the rest; a third for a fitted caption; all of
    it for both when the caption is over the icon.
  • The edges: a caption too large for the button is drawn alone; an icon without a caption
    takes the whole button and needs no /DA; a caption without a /DA leaves the button as it
    was.
  • A new stream whenever an icon is drawn, and never a write into a stream that is one of the
    widget's icons.
  • Who this touches: only buttons other apps made. The engine writes layouts 0 and 1.

Commit 3: after review, a redraw and a setter write nothing another widget may share.

  • A push button's appearance is a new stream on every redraw, as a check box's are. The
    stream it had is not written into and not opened for writing. Before, a caption-only redraw
    wrote into it. When /AP /N was the icon itself and the icon had been cleared, that drew the
    caption into the picture another widget still showed. And /XObject /FRM stayed in the
    reused stream's resources, which kept a cleared picture in a full save.
  • A widget's own /AP. Before a form drawer replaces an appearance, a widget whose /AP is
    an indirect object, which another widget may name too, gets a copy (OwnAppearanceDict), as
    a placed drawing already did. Push button, check box, radio button and signature box.
  • A widget's own /MK. Every /MK setter writes the annotation's own
    (OwnMKForWriting): icon, colour, text, text position and rotation. A call that changes
    nothing copies nothing.
  • An icon is a form XObject everywhere. For an entry that names an image,
    EPDFAnnot_GetMKIcon gives 0, EPDFAnnot_HasMKIcon false, and the generator draws none.

Unchanged: what every other field draws; text fields, combo boxes and list boxes still write
into the stream they have; a push button that has no /AP (a render still draws nothing for
it); EPDFAnnot_SetAppearanceFromPage; and upstream's files.

Tests

fpdfsdk/epdf_widget_drawing_embeddertest.cpp, 48 tests, and
EPDFSignatureEmbedderTest.PlacingADrawingAgainLeavesTheSignedRevisionAlone, all listed as
layer-mode writers.

  • Drawings: the same picture as ten stamps, ten marks and ten image fields is one drawing in
    a full and in an incremental save. A mark placed by drawing is the wrapper a page fitted today
    gets, at every turn and with every fit. A reopened file's drawing is found and placed again. A
    mark in a file saved before this change reads as a drawing. Every subtype but a stamp and a
    widget is refused with nothing written. Listing decodes no appearance that draws no form and
    writes nothing, on a signed file and inside a layer. After a signature, placing the drawing
    again changes only the widgets it is placed in.

  • Layouts 2 to 6: a table over the five layouts by rectangles and by pixels; the border
    inset, the /IF fits, a turned button and a button on a turned page in each; the edges; and
    AButtonIsSharedAsTheFormFillerSharesIt, which runs upstream's form filler and ours on the
    same seven buttons, at a font size of 12 and at a fitted one, and compares where the icon lands
    and where the caption starts.

  • After review: a cleared icon that was the appearance is not written into, and a cleared
    picture is in no full save, in every layout. A widget keeps an /MK it shares when the other
    is written (every setter), and an /AP it shares when the other is drawn again (push button,
    check box, signature box). On a layer a redraw copies no old appearance and no picture. An
    icon entry that names an image is no icon.

Checked

Unit Embedder
Linux x64, in Docker with the release's image 1409 passed 1893 passed, none failed
macOS arm64 1402 passed 1879 passed, 12 failed

The 12 macOS failures are rendering goldens that fail the same on embedpdf/main. The whole
suite in layer mode on Linux has no unexplained failure and no unknown writer among the tests the
release runs. check-globals.py passes on the Linux x64 library. The pixel runner on macOS gives
the same 53 files as embedpdf/main. check-fork-tags.py --strict and check-c-api.py pass.
Saved files pass qpdf --check and open in macOS Quick Look; our seven-layout page and the one
PDFium's form filler draws give the same image.

Left

  • Acrobat on the saved files.
  • A border given by /Border alone is still drawn 1 wide in every form field, where PDFium's
    form filler draws it as wide as it says. A change of its own, for every field.
  • Release and the pin in embed-pdf-viewer. The pin changes the engine's calls to the three
    renamed functions and regenerates its bindings in the same commit, and binds the four
    /MK icon functions.

A picture is the same thing wherever it shows: a form the document holds
once, with a small placement around it. Only stamps worked that way. A
mark in a signature field was imported again for every widget, so the
same 17 KB picture in ten fields saved as 504 KB, where ten stamps of it
save as 56 KB. And the fork could not write a push button's icon at all,
which is what a field that holds a picture is in a file: /MK /TP 1, the
picture as a form XObject in /MK /I, and an /AP /N that draws it.

Drawings serve widgets now:
- EPDFAnnot_SetDrawing (was EPDFAnnot_SetStampDrawing) places a drawing in
  a widget as it does on a stamp: a new wrapper, fitted and turned exactly
  as EPDFAnnot_UpdateAppearanceToRect fits a widget's mark (/Rect and
  /MK /R, neither written). It checks the drawing and the box before it
  opens the annotation for writing. It takes a stamp and a widget.
- EPDFAnnot_GetDrawing (was EPDFAnnot_GetStampDrawing) reads a widget's
  wrapper too, a mark placed the old way included.
- EPDFAnnot_SetMKIcon, GetMKIcon, ClearMKIcon and HasMKIcon name, read
  and remove a widget's /MK icons (/I, /RI, /IX) by drawing.
- EPDFDoc_GetDrawings (was EPDFDoc_GetStampDrawings) also lists the
  drawings widgets' marks place and the forms /MK names as icons, so a
  reopened file's pictures are found and placed again. An appearance
  whose resources name no XObject is not decoded for it, and it writes
  nothing.
A drawing is only read by a placement, so one an earlier revision holds
can be placed after a signature without touching it.

The generator draws a push button with /MK /TP 1 from its normal icon
(GenerateIconButtonAP): the background and border, then the icon inside
the border's width, or in the whole button when /MK /IF /FB says so,
clipped there. The fit is the file's /MK /IF (ISO 32000-2 Table 250), and
the table's defaults without one. It is read through upstream's
CPDF_IconFit and worked out in ours: upstream's placement puts an icon
whose fit names no /A at the bottom left. The icon's box is its /BBox
through its /Matrix. The button is laid out in the frame its /MK /R
gives. The appearance names the icon /FRM, as Acrobat does, so the file
holds the picture once. It draws no caption and needs no /DA, it is a new
stream, and the generator can draw it in memory as well.

The engine's calls to the three renamed functions change with the pin.

A push button in the layouts that show a caption and an icon (/MK /TP 2
to 6) is drawn as it was: the caption, without the icon.
A push button in a layout that shows a caption and an icon (/MK /TP 2 to
6) was drawn as its caption alone, so a button another app made lost its
picture from the appearance when it was drawn again. /MK /I still named
it.

The generator draws both now. The button inside its border, or the whole
button when /MK /IF /FB says so, is shared by the rule of PDFium's form
filler (GetPushButtonAppStream), so a button looks the same whichever
drew it: the caption takes a strip as high as its line below or above the
icon, or as wide as its text right or left of it, and the icon the rest.
A caption whose size is fitted (a font size of 0) takes a third. Over the
icon both take all of it, and the caption is drawn last. The icon is
fitted into its part as /MK /IF says, by the placement an icon alone
gets, and the caption is drawn as the caption-only layout draws it, in
the middle of its part.

A caption that needs more than the button has is drawn alone, as the form
filler draws it. A button with an icon and no caption draws the icon in
the whole button and needs no /DA. A button with a caption and no /DA is
left as it was, as every field that shows text is.

An appearance that draws an icon is a new stream: the one the widget had
may be another widget's, and its resources may be shared. No appearance
is written into a stream that is one of the widget's icons, in any
layout.

The engine writes the caption-only and the icon-only layouts, so this
touches only buttons other apps made. Upstream's files are unchanged; a
test runs upstream's form filler on the same buttons and compares the
two.
@bobsingor
bobsingor force-pushed the embedpdf/feature/button-icon branch from c4cbdea to 1d687e1 Compare November 22, 2026 19:02
A review of this pull request found five ways a button's redraw or an /MK
setter reached something another widget may still use, or kept something
the file should no longer hold.

A push button that draws its caption alone wrote into the stream it had.
When that stream was the button's icon itself, as another app may write
one, and the icon had been cleared (EPDFAnnot_ClearMKIcon), the caption
was drawn into the picture, and a second button that showed the picture
went blank. And a button drawn with a caption and an icon kept /XObject
/FRM in the reused stream's resources after its icon was cleared, so a
full save still held the picture. A push button's appearance is a new
stream on every redraw now, as a check box's are. The stream it had is
neither written into nor opened for writing, so nothing of it is copied
into a layer either.

Two widgets may name one indirect /AP. Replacing /N in it showed the new
appearance in both. Before a form drawer replaces an appearance, the
widget gets a copy of the /AP as its own (OwnAppearanceDict), as a placed
drawing's appearance already does (SetDetachedNormalAppearance). This
covers the push button, the check box, the radio button and the box of a
signature field.

Two widgets may name one indirect /MK. EPDFAnnot_SetMKIcon and
EPDFAnnot_ClearMKIcon changed both, and so did every older /MK setter:
colour, text, text position and rotation. Each writes the annotation's
own /MK now (OwnMKForWriting), and a call that changes nothing copies
nothing. EPDFAnnot_ClearMKColor no longer writes when there is nothing to
remove.

An /MK /I that names an image, not a form, was read as an icon by
EPDFAnnot_GetMKIcon and EPDFAnnot_HasMKIcon, though the list leaves it
out and the export refuses it. An icon is a form XObject everywhere now:
the getter gives 0 for anything else, and the generator draws none.

Text fields, combo boxes and list boxes still write into the stream they
have. A border given by /Border alone is still drawn 1 wide in every form
field: that is a change of its own, for every field.
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