Skip to content

Commit

Permalink
Merge pull request #14152 from Snuffleupagus/xfaFactory-typo
Browse files Browse the repository at this point in the history
Fix a `xfaFaxtory` typo in the shadowing in the  `PDFDocument.xfaFactory` getter, and some other clean-up
  • Loading branch information
timvandermeij authored Oct 16, 2021
2 parents 9890f35 + 0041230 commit 52fce0d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
18 changes: 10 additions & 8 deletions src/core/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ class Catalog {

get version() {
const version = this._catDict.get("Version");
if (!isName(version)) {
return shadow(this, "version", null);
}
return shadow(this, "version", version.name);
return shadow(
this,
"version",
version instanceof Name ? version.name : null
);
}

/**
Expand All @@ -94,10 +95,11 @@ class Catalog {
*/
get needsRendering() {
const needsRendering = this._catDict.get("NeedsRendering");
if (!isBool(needsRendering)) {
return shadow(this, "needsRendering", false);
}
return shadow(this, "needsRendering", needsRendering);
return shadow(
this,
"needsRendering",
typeof needsRendering === "boolean" ? needsRendering : false
);
}

get collection() {
Expand Down
42 changes: 21 additions & 21 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,13 @@ class Page {
}

get xfaData() {
if (this.xfaFactory) {
return shadow(this, "xfaData", {
bbox: this.xfaFactory.getBoundingBox(this.pageIndex),
});
}
return shadow(this, "xfaData", null);
return shadow(
this,
"xfaData",
this.xfaFactory
? { bbox: this.xfaFactory.getBoundingBox(this.pageIndex) }
: null
);
}

save(handler, task, annotationStorage) {
Expand Down Expand Up @@ -784,11 +785,14 @@ class PDFDocument {
}

get numPages() {
let num = 0;
if (this.xfaFactory) {
return shadow(this, "numPages", this.xfaFactory.numberPages);
num = this.xfaFactory.numPages;
} else if (this.linearization) {
num = this.linearization.numPages;
} else {
num = this.catalog.numPages;
}
const linearization = this.linearization;
const num = linearization ? linearization.numPages : this.catalog.numPages;
return shadow(this, "numPages", num);
}

Expand Down Expand Up @@ -883,27 +887,24 @@ class PDFDocument {
}

get xfaFactory() {
let data;
if (
this.pdfManager.enableXfa &&
this.catalog.needsRendering &&
this.formInfo.hasXfa &&
!this.formInfo.hasAcroForm
) {
const data = this.xfaData;
return shadow(this, "xfaFactory", data ? new XFAFactory(data) : null);
data = this.xfaData;
}
return shadow(this, "xfaFaxtory", null);
return shadow(this, "xfaFactory", data ? new XFAFactory(data) : null);
}

get isPureXfa() {
return this.xfaFactory && this.xfaFactory.isValid();
return this.xfaFactory ? this.xfaFactory.isValid() : false;
}

get htmlForXfa() {
if (this.xfaFactory) {
return this.xfaFactory.getPages();
}
return null;
return this.xfaFactory ? this.xfaFactory.getPages() : null;
}

async loadXfaImages() {
Expand Down Expand Up @@ -1084,10 +1085,9 @@ class PDFDocument {
}

async serializeXfaData(annotationStorage) {
if (this.xfaFactory) {
return this.xfaFactory.serializeData(annotationStorage);
}
return null;
return this.xfaFactory
? this.xfaFactory.serializeData(annotationStorage)
: null;
}

get formInfo() {
Expand Down
2 changes: 1 addition & 1 deletion src/core/xfa/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class XFAFactory {
return this.dims[pageIndex];
}

get numberPages() {
get numPages() {
if (!this.pages) {
this._createPages();
}
Expand Down
28 changes: 14 additions & 14 deletions test/unit/xfa_tohtml_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("XFAFactory", function () {
const factory = new XFAFactory({ "xdp:xdp": xml });
factory.setFonts([]);

expect(factory.numberPages).toEqual(2);
expect(factory.numPages).toEqual(2);

const pages = factory.getPages();
const page1 = pages.children[0];
Expand Down Expand Up @@ -174,7 +174,7 @@ describe("XFAFactory", function () {
`;
const factory = new XFAFactory({ "xdp:xdp": xml });

expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);

const pages = factory.getPages();
const field = searchHtmlNode(pages, "name", "img");
Expand Down Expand Up @@ -208,7 +208,7 @@ describe("XFAFactory", function () {
`;
const factory = new XFAFactory({ "xdp:xdp": xml });

expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);

const pages = factory.getPages();
const page1 = pages.children[0];
Expand Down Expand Up @@ -263,7 +263,7 @@ describe("XFAFactory", function () {
const factory = new XFAFactory({ "xdp:xdp": xml });
factory.setFonts([]);

expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);

const pages = factory.getPages();
const table = searchHtmlNode(
Expand Down Expand Up @@ -336,7 +336,7 @@ describe("XFAFactory", function () {
`;
const factory = new XFAFactory({ "xdp:xdp": xml });

expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);

const pages = factory.getPages();
const field = searchHtmlNode(pages, "name", "input");
Expand Down Expand Up @@ -378,7 +378,7 @@ describe("XFAFactory", function () {
`;
const factory = new XFAFactory({ "xdp:xdp": xml });

expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);

const pages = factory.getPages();
const field = searchHtmlNode(pages, "name", "input");
Expand Down Expand Up @@ -420,7 +420,7 @@ describe("XFAFactory", function () {
`;
const factory = new XFAFactory({ "xdp:xdp": xml });

expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);

const pages = factory.getPages();
const field = searchHtmlNode(pages, "name", "input");
Expand Down Expand Up @@ -463,7 +463,7 @@ describe("XFAFactory", function () {
`;
const factory = new XFAFactory({ "xdp:xdp": xml });

expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);

const pages = factory.getPages();
const field1 = searchHtmlNode(pages, "name", "input");
Expand Down Expand Up @@ -517,7 +517,7 @@ describe("XFAFactory", function () {
`;
const factory = new XFAFactory({ "xdp:xdp": xml });

expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);

const pages = factory.getPages();
const field1 = searchHtmlNode(pages, "name", "input");
Expand Down Expand Up @@ -560,31 +560,31 @@ describe("XFAFactory", function () {

// A valid, and complete, URL.
factory = new XFAFactory({ "xdp:xdp": getXml("https://www.example.com/") });
expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);
pages = factory.getPages();
a = searchHtmlNode(pages, "name", "a");
expect(a.value).toEqual("https://www.example.com/");
expect(a.attributes.href).toEqual("https://www.example.com/");

// A valid, but incomplete, URL.
factory = new XFAFactory({ "xdp:xdp": getXml("www.example.com/") });
expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);
pages = factory.getPages();
a = searchHtmlNode(pages, "name", "a");
expect(a.value).toEqual("www.example.com/");
expect(a.attributes.href).toEqual("http://www.example.com/");

// A valid email-address.
factory = new XFAFactory({ "xdp:xdp": getXml("mailto:test@example.com") });
expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);
pages = factory.getPages();
a = searchHtmlNode(pages, "name", "a");
expect(a.value).toEqual("mailto:test@example.com");
expect(a.attributes.href).toEqual("mailto:test@example.com");

// Not a valid URL.
factory = new XFAFactory({ "xdp:xdp": getXml("qwerty/") });
expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);
pages = factory.getPages();
a = searchHtmlNode(pages, "name", "a");
expect(a.value).toEqual("qwerty/");
Expand Down Expand Up @@ -635,7 +635,7 @@ describe("XFAFactory", function () {
`;
const factory = new XFAFactory({ "xdp:xdp": xml });

expect(factory.numberPages).toEqual(1);
expect(factory.numPages).toEqual(1);

const pages = factory.getPages();
let a = searchHtmlNode(pages, "name", "a");
Expand Down

0 comments on commit 52fce0d

Please sign in to comment.