mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 23:58:07 +02:00
Don't store complex data in PDFDocument.formInfo
, and replace the fields
object with a hasFields
boolean instead
*This patch is based on a couple of smaller things that I noticed when working on PR 12479.* - Don't store the /Fields on the `formInfo` getter, since that feels like overloading it with unintended (and too complex) data, and utilize a `hasFields` boolean instead. This functionality was originally added in PR 12271, to help determine what kind of form data a PDF document contains, and I think that we should ensure that the return value of `formInfo` only consists of "simple" data. With these changes the `fieldObjects` getter instead has to look-up the /Fields manually, however that shouldn't be a problem since the access is guarded by a `formInfo.hasFields` check which ensures that the data both exists and is valid. Furthermore, most documents doesn't even have any /AcroForm data anyway. - Determine the `hasFields` property *first*, to ensure that it's always correct even if there's errors when checking e.g. the /XFA or /SigFlags entires, since the `fieldObjects` getter depends on it. - Simplify a loop in `fieldObjects`, since the object being accessed is a `Map` and those have built-in iteration support. - Use a higher logging level for errors in the `formInfo` getter, and include the actual error message, since that'd have helped with fixing PR 12479 a lot quicker. - Update the JSDoc comment in `src/display/api.js` to list the return values correctly, and also slightly extend/improve the description.
This commit is contained in:
parent
b710fbcb00
commit
3351d3476d
3 changed files with 22 additions and 24 deletions
|
@ -64,7 +64,7 @@ describe("document", function () {
|
|||
expect(pdfDocument.formInfo).toEqual({
|
||||
hasAcroForm: false,
|
||||
hasXfa: false,
|
||||
fields: null,
|
||||
hasFields: false,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -77,7 +77,7 @@ describe("document", function () {
|
|||
expect(pdfDocument.formInfo).toEqual({
|
||||
hasAcroForm: false,
|
||||
hasXfa: false,
|
||||
fields: null,
|
||||
hasFields: false,
|
||||
});
|
||||
|
||||
acroForm.set("XFA", ["foo", "bar"]);
|
||||
|
@ -85,7 +85,7 @@ describe("document", function () {
|
|||
expect(pdfDocument.formInfo).toEqual({
|
||||
hasAcroForm: false,
|
||||
hasXfa: true,
|
||||
fields: null,
|
||||
hasFields: false,
|
||||
});
|
||||
|
||||
acroForm.set("XFA", new StringStream(""));
|
||||
|
@ -93,7 +93,7 @@ describe("document", function () {
|
|||
expect(pdfDocument.formInfo).toEqual({
|
||||
hasAcroForm: false,
|
||||
hasXfa: false,
|
||||
fields: null,
|
||||
hasFields: false,
|
||||
});
|
||||
|
||||
acroForm.set("XFA", new StringStream("non-empty"));
|
||||
|
@ -101,7 +101,7 @@ describe("document", function () {
|
|||
expect(pdfDocument.formInfo).toEqual({
|
||||
hasAcroForm: false,
|
||||
hasXfa: true,
|
||||
fields: null,
|
||||
hasFields: false,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -114,7 +114,7 @@ describe("document", function () {
|
|||
expect(pdfDocument.formInfo).toEqual({
|
||||
hasAcroForm: false,
|
||||
hasXfa: false,
|
||||
fields: null,
|
||||
hasFields: false,
|
||||
});
|
||||
|
||||
acroForm.set("Fields", ["foo", "bar"]);
|
||||
|
@ -122,7 +122,7 @@ describe("document", function () {
|
|||
expect(pdfDocument.formInfo).toEqual({
|
||||
hasAcroForm: true,
|
||||
hasXfa: false,
|
||||
fields: ["foo", "bar"],
|
||||
hasFields: true,
|
||||
});
|
||||
|
||||
// If the first bit of the `SigFlags` entry is set and the `Fields` array
|
||||
|
@ -133,7 +133,7 @@ describe("document", function () {
|
|||
expect(pdfDocument.formInfo).toEqual({
|
||||
hasAcroForm: true,
|
||||
hasXfa: false,
|
||||
fields: ["foo", "bar"],
|
||||
hasFields: true,
|
||||
});
|
||||
|
||||
const annotationDict = new Dict();
|
||||
|
@ -156,7 +156,7 @@ describe("document", function () {
|
|||
expect(pdfDocument.formInfo).toEqual({
|
||||
hasAcroForm: false,
|
||||
hasXfa: false,
|
||||
fields: [kidsRef],
|
||||
hasFields: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue