Skip to content

Read an annotation's border in one place, for form fields and setters too - #130

Merged
bobsingor merged 4 commits into
embedpdf/mainfrom
embedpdf/fix/one-border-rule
Nov 24, 2026
Merged

bobsingor merged 4 commits into
embedpdf/mainfrom
embedpdf/fix/one-border-rule

Conversation

@bobsingor

Copy link
Copy Markdown
Contributor

Cause

ISO 32000-1 12.5.2 reads an annotation's border from /BS when it has one, and then /Border is not read at all; else from /Border [h v w [dash]]; else the border is solid and 1 wide. #118 and #121 made free text follow that. The rule was then written four times (three readers in the generator's common file, and the C API getters), and two places did not follow it.

  • Form fields. Every form field drawer read /BS alone: text field, combo box, list box, push button, check box, radio button and the signature box. A field with /Border [0 0 5 [4 2]] and no /BS was drawn 1 wide and solid, and one with /Border [0 0 0] was drawn 1 wide, while EPDFAnnot_GetBorderStyle read 5 and dashed, and 0. What the API read and what a redraw drew did not agree.
  • Setters, on an annotation whose border is only in /Border:
    • EPDFAnnot_SetBorderDashPattern with a pattern made a /BS holding only /D, so the width fell from the array's to 1.
    • EPDFAnnot_SetBorderDashPattern with no pattern changed nothing: the array's dash stayed.
    • EPDFAnnot_SetBorderStyle wrote /BS and left the old /Border in the file. A reader that looks at /Border first (PDFium's form filler does) went on showing the old border, and the array's dash pattern was lost to every reader that follows ISO.

Change

  • One reader. fpdfdoc::ReadAnnotBorder (core/fpdfdoc/cpdf_annot_border.{h,cpp}) reads the width, the style and the stored dash pattern by the rule. GetAnnotBorderStyleInfo, GetBorderWidth and GetDashPatternString in the generator, and EPDFAnnot_GetBorderStyle and the two dash pattern readers in the C API, all take the border from it. The reader of a bare /BS dictionary is gone, so a drawer can't read /BS alone again.
  • Drawers. The seven form field drawers and the link's style read call GetAnnotBorderStyleInfo(annot_dict).
  • Setters. Before EPDFAnnot_SetBorderStyle or EPDFAnnot_SetBorderDashPattern changes an annotation that has no /BS, its /Border is written into a new /BS as it reads: its width, and a dashed style with its pattern when the array has one. The setter then changes the part it sets, as it does on any /BS, and /Border is removed (also when it stood beside a /BS). So the dash setter changes the pattern and leaves the style alone there too: a pattern set on a solid /Border is stored and the border stays solid, and a pattern removed from a dashed one leaves a dashed border that draws the default dash. EPDFAnnot_SetBorderStyle refuses a style that is none before it writes anything.
  • The ledger has the rule and its guard under own-appearance-generator. The comments of the getter and both setters in public/epdf_annot.h say what they do with a /Border.

What each kind draws:

Kind /BS, both keys, or neither key Border only in /Border
Square, circle, line, polygon, polyline, ink, free text plain and callout, link, redaction Byte for byte as before Byte for byte as before
Text field, combo box, list box, signature Byte for byte as before The array's width, its dash, and no border at width 0 (was 1 wide and solid)
Check box, radio button, push button Byte for byte as before The array's width, and no border at width 0 (was 1 wide). A dash is not drawn from either key: see Left

Three readings changed so that every reader agrees, all on input ISO does not define:

  • A /BS /S that is none of ISO's five names (/Dashed, /Underline) is solid everywhere. The form fields, the plain free text box and the link took its first letter, so /S /Unknown drew an underline while the API read solid.
  • A /Border with more than four entries has no dash for the API either; it had none for the drawing.
  • A /BS /S written as a string is the style for the API too, as it was for the drawing.

Tests

  • CPDFGenerateAPTest.BorderArrayDrawsAsBorderStyleForEveryKind: for all seventeen kinds, the stream drawn from /Border equals the stream drawn from /BS at width 5, with dash [4 2] and at width 0; neither key draws as /BS /W 1; /BS wins when both are there.
  • CPDFAnnotBorderTest.*, five tests of the reader.
  • EPDFAnnotEmbedderTest.SettingADashOnABorderArrayKeepsItsWidth, RemovingTheDashOfABorderArrayKeepsItsWidth and SettingABorderStyleRemovesTheBorderArray: the setters, read back through the API and drawn.
  • EPDFAnnotEmbedderTest.AFormFieldDrawsTheBorderItReads: a text field through the C API.
  • The four embedder tests are listed as layer-mode writers. No listed count moved.

Checked

  • macOS: unit 1408 passed; embedder 1834 passed and the 12 golden failures an unchanged build of the base has, test by test the same.
  • Linux x64, in the release image: unit 1415 passed; embedder 1848 passed, 4 skipped, none failed.
  • The whole suite in layer mode on Linux, as the release runs it: nothing reported for this change.
  • On the base the table test fails for exactly the seven form field kinds, in the three /Border comparisons, and the setter and widget tests fail.
  • A dump of all seventeen kinds over 28 borders, base against new: with /BS, both keys or neither, nothing differs for ISO's style names; with only /Border, only the seven form field kinds differ.
  • The C API getters over 31 borders, base against new: the same, apart from the last two readings listed above.
  • The pixel runner's log is identical to the base's. 49 saved PDFs pass the save checker.
  • check-fork-tags.py --strict, check-c-api.py (600 functions), check-globals.py on the macOS and Linux libraries.
  • PDFium's form filler reads a widget's width and dashed style from /Border when there is no /BS, as the generator now does.

Left

  • Release, and the pin in embed-pdf-viewer. The engine needs no change.
  • Acrobat was not checked: how it draws a widget with /Border and no /BS.
  • Push button, check box and radio button draw every border style as a solid box: a dashed or underlined border draws solid, a beveled or inset one a flat line of twice the width. Not part of this change.
  • Show one drawing as a stamp, a mark in a widget and a push button's icon #129 calls the removed /BS reader in GenerateIconButtonAP. Whichever of the two merges second takes the one-line change to GetAnnotBorderStyleInfo(annot_dict), and the icon button gets a row in the table test.

… too

ISO 32000-1 12.5.2 reads an annotation's border from /BS when it has one,
and then /Border is not read at all; else from /Border [h v w [dash]]; else
the border is solid and 1 wide. Free text has followed that since pull
requests 118 and 121. The rule was then written four times, and two places
did not follow it.

Every form field drawer read /BS alone: text field, combo box, list box,
push button, check box, radio button and the signature box. A field with
/Border [0 0 5 [4 2]] and no /BS was drawn 1 wide and solid, and one with
/Border [0 0 0] was drawn 1 wide, while EPDFAnnot_GetBorderStyle read 5 and
dashed, and 0: what the API read and what a redraw drew did not agree.

On an annotation whose border is only in /Border,
EPDFAnnot_SetBorderDashPattern made a /BS holding only /D, so the width
fell to 1, and with no pattern it changed nothing. EPDFAnnot_SetBorderStyle
left the old /Border in the file, where a reader that looks at /Border
first (PDFium's form filler does) went on showing the old border.

fpdfdoc::ReadAnnotBorder (core/fpdfdoc/cpdf_annot_border) now reads the
width, the style and the stored dash pattern by the rule. The generator's
GetAnnotBorderStyleInfo, GetBorderWidth and GetDashPatternString, and the C
API's EPDFAnnot_GetBorderStyle and dash pattern readers, take the border
from it. The reader of a bare /BS dictionary is gone, so a drawer can't
read /BS alone again; the form field drawers and the link's style read
call GetAnnotBorderStyleInfo.

Before a setter changes an annotation that has no /BS, its /Border is
written into a new /BS as it reads: its width, and a dashed style with its
pattern when the array has one. The setter then changes the part it sets,
as it does on any /BS, so the dash setter leaves the style alone there too,
and /Border is removed. EPDFAnnot_SetBorderStyle refuses a style that is
none before it writes anything.

With one reading, three inputs ISO does not define read alike everywhere.
A /BS /S that is none of its five names is solid: the form fields, the
plain free text box and the link took its first letter. A /Border with
more than four entries has no dash for the API either. A /BS /S written as
a string is the style for the API too.

Tests: CPDFGenerateAPTest.BorderArrayDrawsAsBorderStyleForEveryKind draws
all seventeen kinds that have a border from /BS and from /Border and
compares the streams. CPDFAnnotBorderTest covers the reader. Three
EPDFAnnotEmbedderTest cases cover the setters and one a text field through
the C API; the four are listed as layer-mode writers.
…/one-border-rule

Main has pull request 129 (a push button's icon). Two files conflicted:
core/fpdfdoc/cpdf_appearancegenerator_forms.cpp, where 129 reshaped the
push button drawer around the line this branch changed, and the ledger's
own-appearance-generator rule, which both sides extended.

129's icon button drawer called the reader of a bare /BS that this branch
removes. In the merged tree GenerateIconButtonAP takes the border from
GetAnnotBorderStyleInfo(annot_dict), as every other form field drawer does.
A review of pull request 130 found three things in the border setters.

A call that asked for what the border already was still turned a /Border
into a /BS and removed it. On /Border [6 4 2], removing a dash pattern that
is not there left /BS << /W 2 >>, and the corner radii, which a /BS cannot
hold, were gone. Setting the style and width it has, the pattern it has, or
dashed on a dashed one did the same. EPDFAnnot_SetBorderStyle and
EPDFAnnot_SetBorderDashPattern now read what the border states first
(ReadStatedBorder) and write nothing when that is what the call asks for.
A /BS states its entries, so a call for an entry it leaves out still writes
it. A /Border states width, style and pattern by its form. Only a key that
is well formed states anything: a name where the width goes reads as 0, and
is written anew. A call that changes the border still moves a /Border into
/BS and removes it.

A style that is none was refused after the annotation had been taken for
writing, so on a layer the annotation was copied in for nothing. The check
is above that now, and a call that changes nothing copies nothing either.

A /BS that is an indirect object may be another annotation's too, and so
may its /D. The setters wrote into both. The annotation now gets a /BS of
its own first (OwnDictEntry, which OwnMKForWriting uses for /MK too), and a
pattern goes into a new array under /D.

The table test over every kind that has a border gains a row for a push
button that shows its icon, whose drawer reads the border through the one
reader since the merge.

Tests, in EPDFAnnotEmbedderTest and listed as layer-mode writers:
ABorderCallThatChangesNothingWritesNothing,
ABorderCallThatChangesNothingLeavesALayerAsItWas,
AMalformedBorderThatReadsAsAskedIsWrittenAnew,
ARefusedBorderStyleLeavesALayerAsItWas and
ASharedBorderStyleIsNotWrittenInto.
RemovingTheDashOfABorderArrayKeepsItsWidth now expects a solid /Border to
stay when its absent pattern is removed.
The border setters skip a call that asks for what the border already
states. To see what it states they looked each entry up by the object it
names, which is nothing both for a key that is left out and for a reference
to an object the file does not have. The reader goes by the key, and reads
such a /W as 0.

So on /BS << /S /S /W 9 0 R >> with no object 9, a call that leaves the
width out (a negative width) found nothing to do and returned true, and the
border went on reading 0 wide where the call's contract says 1. A /S or a
/D that names nothing was left in place the same way, and so was a /BS or a
/Border that names nothing, though without a wrong reading.

ReadStatedBorder now looks for each entry by its key. One that is there and
does not name a number, a name or an array of numbers is malformed, as a
name where a number goes already was, and the setter writes the border
anew.

Test: EPDFAnnotEmbedderTest.ABorderEntryThatNamesNothingIsNotLeftOut,
listed as a layer-mode writer. Five of its six cases fail without the
change.
@bobsingor
bobsingor merged commit f596d90 into embedpdf/main Nov 24, 2026
1 check passed
@bobsingor
bobsingor deleted the embedpdf/fix/one-border-rule branch November 24, 2026 21:49
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