Repository navigation
Fit a widget's mark by its /MK /R turn, and draw a field with a negative /R - #123
Merged
Merged
Conversation
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.
This was referenced Nov 17, 2026
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.
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.
Two places read a widget's
/MK /Rwrongly, each in its own commit.EPDFAnnot_SetAppearanceFromPageandEPDFAnnot_UpdateAppearanceToRect) was fitted into/Rectas the field stands, whatever/MK /Rsaid. 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./MK /Rwas not drawn at all. The field drawing switched on/MK /Rmodulo 360 with cases 0, 90, 180 and 270, and in C++-90 % 360is-90, so the box stayed empty. Acrobat draws/MK /R -90as it draws 270 (checked by hand on Nov 17 2026), and the engine reads it so.Change
One reading of
/MK /R. Newfpdfdoc::GetMKRotationDegrees(core/fpdfdoc/cpdf_annot_rotation.{h,cpp}) brings the number into [0, 360), so-90is270. Both readers below take it.A mark in a turned field (first commit).
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_Metadataas it did.PlaceWrapperthen writes the box as the wrapper's/BBoxand 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./Rectand/MKare read, never written (PlacementBox::writes_rect). An unturned widget's appearance is what it was.PlaceWrapperbuilds its turn withfpdfdoc::TurnAbout, which is exact at quarter turns. This changes a stamp's bytes at exactly 90, 180 and 270: its wrapper's/Matrixand its/Rectget whole numbers, wherecosfandsinfleft 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
/Matrixholding 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 afterEPDFAnnot_SetAppearanceFromPage.A field with a negative
/MK /R(second commit).GetAppearanceCharacteristics(cpdf_appearancegenerator_forms.cpp) reads the turn throughGetMKRotationDegrees, andGetAnnotationDimensionsAndColor(cpdf_appearancegenerator_common.cpp) switches on it. A field with/MK /R -90is drawn as it is at 270.cpdf_generateap.cpphas the same switch and stays as upstream wrote it (own-appearance-generator)./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 /R90, 270, -90 and 180 on a widget that stands 40 by 160. The wrapper's/BBoxis the box, its/Matrixthe quarter turn, the mark is fitted into the box, and/Rectand/MK /Rare what they were.EPDFStampResizeEmbedderTest.AWidgetsMarkWithoutAQuarterTurnFillsRect: no/MK,/R 0,/R 360and/R 45fit the mark into/Rectwith no/Matrix.EPDFStampResizeEmbedderTest.ATurnedWidgetsOwnAppearanceIsTurnedOnce: a form with the turn in its/Matrixis 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-90written as a file would hold it, has the same/BBox,/Matrixand content.Both commits, full suites:
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 /Rand no stored appearance; no file undertesting/resourcesnames such an/MKin plain text.check-fork-tags.pypasses; the changed files are the fork's own, so the ledger needs no rule.