Repository navigation
Conversation
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
force-pushed
the
embedpdf/feature/button-icon
branch
from
November 22, 2026 19:02
c4cbdea to
1d687e1
Compare
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
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 /Nthat draws it; animage 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.
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_SetDrawingplaces a drawing in a widget as it does on a stamp, fitted andturned exactly as
EPDFAnnot_UpdateAppearanceToRectfits a widget's mark.EPDFAnnot_GetDrawingreads it back, a mark placed the old way included. Both take a stampand a widget, and no other subtype.
EPDFAnnot_SetMKIcon,EPDFAnnot_GetMKIcon,EPDFAnnot_ClearMKIconandEPDFAnnot_HasMKIconfor/MK /I,/RIand/IX.EPDFDoc_GetDrawingsalso lists the drawings widgets' marks place and the forms/MKnames as icons. An appearance whose resources name no XObject is not decoded, andlisting writes nothing.
EPDFAnnot_SetDrawingchecks before it opens theannotation for writing. A drawing an earlier revision holds can be placed after a signature.
/MK /I(GenerateIconButtonAP): insidethe border, fitted by
/MK /IFor by the PDF's defaults, in the frame/MK /Rgives, by theicon's
/BBoxthrough its/Matrix. No caption and no/DAare needed.Commit 2: a caption and an icon together (
/MK /TP2 to 6).(
GetPushButtonAppStream): a strip as high as the caption's line below or above the icon, oras 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.
takes the whole button and needs no
/DA; a caption without a/DAleaves the button as itwas.
widget's icons.
Unchanged: every other field, a push button that has no
/AP(a render still draws nothingfor it),
EPDFAnnot_SetAppearanceFromPage, and upstream's files.Tests
fpdfsdk/epdf_widget_drawing_embeddertest.cpp, 42 tests, andEPDFSignatureEmbedderTest.PlacingADrawingAgainLeavesTheSignedRevisionAlone, all listed aslayer-mode writers.
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.
inset, the
/IFfits, a turned button and a button on a turned page in each; the edges; andAButtonIsSharedAsTheFormFillerSharesIt, which runs upstream's form filler and ours on thesame seven buttons, at a font size of 12 and at a fitted one, and compares where the icon lands
and where the caption starts.
Checked
The 12 macOS failures are rendering goldens that fail the same on
embedpdf/main. The wholesuite in layer mode on Linux has no unexplained failure and no unknown writer among the tests the
release runs.
check-globals.pypasses on the Linux x64 library. The pixel runner on macOS givesthe same 53 files as
embedpdf/main.check-fork-tags.py --strictandcheck-c-api.pypass.Saved files pass
qpdf --checkand open in macOS Quick Look; our seven-layout page and the onePDFium's form filler draws give the same image.
Left
renamed functions and regenerates its bindings in the same commit, and binds the four
/MKicon functions.