Skip to content

Fit a widget's mark by its /MK /R turn, and draw a field with a negative /R - #123

Merged
bobsingor merged 2 commits into
embedpdf/mainfrom
embedpdf/fix/widget-mark-turn
Nov 17, 2026
Merged

bobsingor merged 2 commits into
embedpdf/mainfrom
embedpdf/fix/widget-mark-turn

Conversation

@bobsingor

@bobsingor bobsingor commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Two places read a widget's /MK /R wrongly, each in its own commit.

  1. A drawing placed in a widget (a signature field's mark, through EPDFAnnot_SetAppearanceFromPage and EPDFAnnot_UpdateAppearanceToRect) was fitted into /Rect as the field stands, whatever /MK /R said. In a field turned a quarter turn the mark showed sideways, while the field's own contents are turned. The placement read only our own turn metadata (/EMBD_Metadata), which a widget never has.
  2. A field with a negative /MK /R was not drawn at all. The field drawing switched on /MK /R modulo 360 with cases 0, 90, 180 and 270, and in C++ -90 % 360 is -90, so the box stayed empty. Acrobat draws /MK /R -90 as it draws 270 (checked by hand on Nov 17 2026), and the engine reads it so.

Change

One reading of /MK /R. New fpdfdoc::GetMKRotationDegrees (core/fpdfdoc/cpdf_annot_rotation.{h,cpp}) brings the number into [0, 360), so -90 is 270. Both readers below take it.

A mark in a turned field (first commit).

  • New fpdfdoc::GetWidgetAnnotRotation: a widget's turn is that number when it is a quarter turn, and no turn otherwise. Its box is /Rect, normalised, with its sides swapped about its middle at 90 and 270.
  • ReadPlacementBox (fpdfsdk/epdf_annot.cpp) takes a widget's box and turn from it, and a stamp's from /EMBD_Metadata as it did. PlaceWrapper then writes the box as the wrapper's /BBox and the quarter turn as its /Matrix: the matrix a field's own appearance has (GetAnnotationDimensionsAndColor). The mark is fitted into the box, so it reads the way the field's contents do.
  • A widget's /Rect and /MK are read, never written (PlacementBox::writes_rect). An unturned widget's appearance is what it was.
  • PlaceWrapper builds its turn with fpdfdoc::TurnAbout, which is exact at quarter turns. This changes a stamp's bytes at exactly 90, 180 and 270: its wrapper's /Matrix and its /Rect get whole numbers, where cosf and sinf left about 4e-8 of noise. Other angles are written as they were.

A turned widget whose appearance isn't our wrapper (a form another app drew, its /Matrix holding the turn) is wrapped as a stamp Acrobat turned is: the drawing is that form without the matrix, and our wrapper turns it, once. The engine doesn't take that path today: it fits a widget only right after EPDFAnnot_SetAppearanceFromPage.

A field with a negative /MK /R (second commit).

  • Our generator's GetAppearanceCharacteristics (cpdf_appearancegenerator_forms.cpp) reads the turn through GetMKRotationDegrees, and GetAnnotationDimensionsAndColor (cpdf_appearancegenerator_common.cpp) switches on it. A field with /MK /R -90 is drawn as it is at 270.
  • Upstream's cpdf_generateap.cpp has the same switch and stays as upstream wrote it (own-appearance-generator).
  • A value that is no quarter turn, such as /MK /R 45, is drawn as it was: not at all. What Acrobat does with one is not checked yet.

Tests

New embedder tests:

  • EPDFStampResizeEmbedderTest.AWidgetsMarkIsFittedIntoTheBoxItsTurnGives: /MK /R 90, 270, -90 and 180 on a widget that stands 40 by 160. The wrapper's /BBox is the box, its /Matrix the quarter turn, the mark is fitted into the box, and /Rect and /MK /R are what they were.
  • EPDFStampResizeEmbedderTest.AWidgetsMarkWithoutAQuarterTurnFillsRect: no /MK, /R 0, /R 360 and /R 45 fit the mark into /Rect with no /Matrix.
  • EPDFStampResizeEmbedderTest.ATurnedWidgetsOwnAppearanceIsTurnedOnce: a form with the turn in its /Matrix is wrapped without that matrix.
  • EPDFStampResizeEmbedderTest.AQuarterTurnIsWrittenWithoutNoise: a stamp turned 90 has /Matrix [0 1 -1 0 50 0] and a whole-number /Rect.
  • EPDFFormEmbedderTest.ANegativeWidgetRotationIsDrawnAsItsTurn: a field drawn at /MK /R 270, then at -90 written as a file would hold it, has the same /BBox, /Matrix and content.

Both commits, full suites:

Unit Embedder
Linux x64 (Docker, the release's image) 1409 passed 1822 passed, 4 skipped, none failed
macOS arm64 1402 passed 1808 passed, 4 skipped, 12 failed

The 12 macOS failures are the ones the base has on this Mac (golden and progressive-render tests); the same 12 fail on the same tree without this PR's source changes. Each new test was also run without its source change: all fail there except AWidgetsMarkWithoutAQuarterTurnFillsRect, which passes both ways.

Not run: the pixel runner. It renders files and never calls the placement functions, and the second commit changes a picture only for a field with a negative /MK /R and no stored appearance; no file under testing/resources names such an /MK in plain text. check-fork-tags.py passes; the changed files are the fork's own, so the ledger needs no rule.

EPDFAnnot_UpdateAppearanceToRect fitted a drawing in a widget (a
signature field's mark) into /Rect as the field stands, whatever /MK /R
said: in a field turned a quarter turn the mark showed sideways, where
the field's own contents are turned.

GetWidgetAnnotRotation reads a widget's turn from the entries every PDF
app reads: /MK /R, brought into [0, 360) so -90 is 270, and a value
that is no quarter turn is no turn. The box is /Rect with its sides
swapped about its middle at 90 and 270. ReadPlacementBox takes a
widget's box and turn from it, and a stamp's from /EMBD_Metadata as it
did. The wrapper then has the box as its /BBox and the quarter turn as
its /Matrix, the matrix a field's own appearance has. A widget's /Rect
and /MK are read, never written, and an unturned widget's appearance is
what it was.

PlaceWrapper builds its turn with fpdfdoc::TurnAbout, which is exact at
quarter turns: a stamp turned 90, 180 or 270 gets whole numbers in its
/Matrix and /Rect, where cosf and sinf left about 4e-8 of noise. Other
angles are written as they were.
The field drawing switched on /MK /R modulo 360 with cases 0, 90, 180
and 270. In C++ -90 % 360 is -90, so a field with /MK /R -90 got an
empty box and nothing was drawn. Acrobat draws it as it draws 270, and
the engine reads it so.

GetMKRotationDegrees brings /MK /R into [0, 360), and both readers take
it: the field drawing (GetAppearanceCharacteristics) and a widget's
placement box (GetWidgetAnnotRotation). A value that is no quarter turn
is drawn as it was: not at all.
@bobsingor bobsingor changed the title Fit a widget's mark by its /MK /R turn Fit a widget's mark by its /MK /R turn, and draw a field with a negative /R Nov 17, 2026
@bobsingor
bobsingor merged commit e6e557e into embedpdf/main Nov 17, 2026
1 check passed
q158467234 pushed a commit to q158467234/embed-pdf-viewer that referenced this pull request Nov 22, 2026
The release fits a mark in a form widget by the widget's turn
(embedpdf/runtime#123, embedpdf#124). `EPDFAnnot_UpdateAppearanceToRect` on a
widget reads `/MK /R` and fits the drawing into the frame that turn
gives, where it fitted it into `/Rect` with no turn; it never writes a
widget's `/Rect`. A field with a negative `/MK /R` is drawn as that
turn, -90 as 270, as Acrobat shows it. A stamp turned exactly 90, 180
or 270 gets whole numbers in its appearance's `/Matrix` and `/Rect`.

No function is added, so the bindings generated from the release's
headers are the ones already committed. runtime-src moves to the pin.
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