Skip to content

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

Open
bobsingor wants to merge 1 commit into
embedpdf/mainfrom
embedpdf/fix/one-border-rule
Open

bobsingor wants to merge 1 commit 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.
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