Merge pull request #13437 from calixteman/xfa_mv_root
XFA - Move the fake HTML representation of XFA from the worker to the main thread
This commit is contained in:
commit
8c53bf8647
@ -146,8 +146,7 @@ class Page {
|
|||||||
|
|
||||||
_getBoundingBox(name) {
|
_getBoundingBox(name) {
|
||||||
if (this.xfaData) {
|
if (this.xfaData) {
|
||||||
const { width, height } = this.xfaData.attributes.style;
|
return this.xfaData.bbox;
|
||||||
return [0, 0, parseInt(width), parseInt(height)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const box = this._getInheritableProperty(name, /* getArray = */ true);
|
const box = this._getInheritableProperty(name, /* getArray = */ true);
|
||||||
@ -241,7 +240,9 @@ class Page {
|
|||||||
|
|
||||||
get xfaData() {
|
get xfaData() {
|
||||||
if (this.xfaFactory) {
|
if (this.xfaFactory) {
|
||||||
return shadow(this, "xfaData", this.xfaFactory.getPage(this.pageIndex));
|
return shadow(this, "xfaData", {
|
||||||
|
bbox: this.xfaFactory.getBoundingBox(this.pageIndex),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return shadow(this, "xfaData", null);
|
return shadow(this, "xfaData", null);
|
||||||
}
|
}
|
||||||
@ -851,8 +852,11 @@ class PDFDocument {
|
|||||||
return shadow(this, "xfaFaxtory", null);
|
return shadow(this, "xfaFaxtory", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
get isPureXfa() {
|
get htmlForXfa() {
|
||||||
return this.xfaFactory !== null;
|
if (this.xfaFactory) {
|
||||||
|
return this.xfaFactory.getPages();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadXfaFonts(handler, task) {
|
async loadXfaFonts(handler, task) {
|
||||||
|
@ -187,13 +187,13 @@ class WorkerMessageHandler {
|
|||||||
await pdfManager.ensureDoc("checkFirstPage");
|
await pdfManager.ensureDoc("checkFirstPage");
|
||||||
}
|
}
|
||||||
|
|
||||||
const [numPages, fingerprint, isPureXfa] = await Promise.all([
|
const [numPages, fingerprint, htmlForXfa] = await Promise.all([
|
||||||
pdfManager.ensureDoc("numPages"),
|
pdfManager.ensureDoc("numPages"),
|
||||||
pdfManager.ensureDoc("fingerprint"),
|
pdfManager.ensureDoc("fingerprint"),
|
||||||
pdfManager.ensureDoc("isPureXfa"),
|
pdfManager.ensureDoc("htmlForXfa"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (isPureXfa) {
|
if (htmlForXfa) {
|
||||||
const task = new WorkerTask("loadXfaFonts");
|
const task = new WorkerTask("loadXfaFonts");
|
||||||
startWorkerTask(task);
|
startWorkerTask(task);
|
||||||
await pdfManager
|
await pdfManager
|
||||||
@ -203,7 +203,7 @@ class WorkerMessageHandler {
|
|||||||
})
|
})
|
||||||
.then(() => finishWorkerTask(task));
|
.then(() => finishWorkerTask(task));
|
||||||
}
|
}
|
||||||
return { numPages, fingerprint, isPureXfa };
|
return { numPages, fingerprint, htmlForXfa };
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPdfManager(data, evaluatorOptions, enableXfa) {
|
function getPdfManager(data, evaluatorOptions, enableXfa) {
|
||||||
@ -501,12 +501,6 @@ class WorkerMessageHandler {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetPageXfa", function wphSetupGetXfa({ pageIndex }) {
|
|
||||||
return pdfManager.getPage(pageIndex).then(function (page) {
|
|
||||||
return pdfManager.ensure(page, "xfaData");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
handler.on("GetOutline", function wphSetupGetOutline(data) {
|
handler.on("GetOutline", function wphSetupGetOutline(data) {
|
||||||
return pdfManager.ensureCatalog("documentOutline");
|
return pdfManager.ensureCatalog("documentOutline");
|
||||||
});
|
});
|
||||||
|
@ -22,18 +22,35 @@ class XFAFactory {
|
|||||||
try {
|
try {
|
||||||
this.root = new XFAParser().parse(XFAFactory._createDocument(data));
|
this.root = new XFAParser().parse(XFAFactory._createDocument(data));
|
||||||
this.form = new Binder(this.root).bind();
|
this.form = new Binder(this.root).bind();
|
||||||
this.pages = this.form[$toHTML]();
|
this._createPages();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getPage(pageIndex) {
|
_createPages() {
|
||||||
return this.pages.children[pageIndex];
|
this.pages = this.form[$toHTML]();
|
||||||
|
this.dims = this.pages.children.map(c => {
|
||||||
|
const { width, height } = c.attributes.style;
|
||||||
|
return [0, 0, parseInt(width), parseInt(height)];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getBoundingBox(pageIndex) {
|
||||||
|
return this.dims[pageIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
get numberPages() {
|
get numberPages() {
|
||||||
return this.pages.children.length;
|
return this.dims.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPages() {
|
||||||
|
if (!this.pages) {
|
||||||
|
this._createPages();
|
||||||
|
}
|
||||||
|
const pages = this.pages;
|
||||||
|
this.pages = null;
|
||||||
|
return pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
static _createDocument(data) {
|
static _createDocument(data) {
|
||||||
|
@ -695,7 +695,15 @@ class PDFDocumentProxy {
|
|||||||
* @type {boolean} True if only XFA form.
|
* @type {boolean} True if only XFA form.
|
||||||
*/
|
*/
|
||||||
get isPureXfa() {
|
get isPureXfa() {
|
||||||
return this._pdfInfo.isPureXfa;
|
return !!this._transport._htmlForXfa;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Object | null} An object representing a HTML tree structure
|
||||||
|
* to render the XFA, or `null` when no XFA form exists.
|
||||||
|
*/
|
||||||
|
get allXfaHtml() {
|
||||||
|
return this._transport._htmlForXfa;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1253,8 +1261,8 @@ class PDFPageProxy {
|
|||||||
* are {Object} with a name, attributes (class, style, ...), value and
|
* are {Object} with a name, attributes (class, style, ...), value and
|
||||||
* children, very similar to a HTML DOM tree), or `null` if no XFA exists.
|
* children, very similar to a HTML DOM tree), or `null` if no XFA exists.
|
||||||
*/
|
*/
|
||||||
getXfa() {
|
async getXfa() {
|
||||||
return (this._xfaPromise ||= this._transport.getPageXfa(this._pageIndex));
|
return this._transport._htmlForXfa?.children[this._pageIndex] || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1540,7 +1548,6 @@ class PDFPageProxy {
|
|||||||
this.objs.clear();
|
this.objs.clear();
|
||||||
this._annotationsPromise = null;
|
this._annotationsPromise = null;
|
||||||
this._jsActionsPromise = null;
|
this._jsActionsPromise = null;
|
||||||
this._xfaPromise = null;
|
|
||||||
this._structTreePromise = null;
|
this._structTreePromise = null;
|
||||||
this.pendingCleanup = false;
|
this.pendingCleanup = false;
|
||||||
return Promise.all(waitOn);
|
return Promise.all(waitOn);
|
||||||
@ -1576,7 +1583,6 @@ class PDFPageProxy {
|
|||||||
this.objs.clear();
|
this.objs.clear();
|
||||||
this._annotationsPromise = null;
|
this._annotationsPromise = null;
|
||||||
this._jsActionsPromise = null;
|
this._jsActionsPromise = null;
|
||||||
this._xfaPromise = null;
|
|
||||||
this._structTreePromise = null;
|
this._structTreePromise = null;
|
||||||
if (resetStats && this._stats) {
|
if (resetStats && this._stats) {
|
||||||
this._stats = new StatTimer();
|
this._stats = new StatTimer();
|
||||||
@ -2444,6 +2450,8 @@ class WorkerTransport {
|
|||||||
|
|
||||||
messageHandler.on("GetDoc", ({ pdfInfo }) => {
|
messageHandler.on("GetDoc", ({ pdfInfo }) => {
|
||||||
this._numPages = pdfInfo.numPages;
|
this._numPages = pdfInfo.numPages;
|
||||||
|
this._htmlForXfa = pdfInfo.htmlForXfa;
|
||||||
|
delete pdfInfo.htmlForXfa;
|
||||||
loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
|
loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2800,12 +2808,6 @@ class WorkerTransport {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getPageXfa(pageIndex) {
|
|
||||||
return this.messageHandler.sendWithPromise("GetPageXfa", {
|
|
||||||
pageIndex,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getStructTree(pageIndex) {
|
getStructTree(pageIndex) {
|
||||||
return this.messageHandler.sendWithPromise("GetStructTree", {
|
return this.messageHandler.sendWithPromise("GetStructTree", {
|
||||||
pageIndex,
|
pageIndex,
|
||||||
|
@ -57,7 +57,8 @@ describe("XFAFactory", function () {
|
|||||||
|
|
||||||
expect(factory.numberPages).toEqual(2);
|
expect(factory.numberPages).toEqual(2);
|
||||||
|
|
||||||
const page1 = factory.getPage(0);
|
const pages = factory.getPages();
|
||||||
|
const page1 = pages.children[0];
|
||||||
expect(page1.attributes.style).toEqual({
|
expect(page1.attributes.style).toEqual({
|
||||||
height: "789px",
|
height: "789px",
|
||||||
width: "456px",
|
width: "456px",
|
||||||
@ -99,7 +100,7 @@ describe("XFAFactory", function () {
|
|||||||
|
|
||||||
// draw element must be on each page.
|
// draw element must be on each page.
|
||||||
expect(draw.attributes.style).toEqual(
|
expect(draw.attributes.style).toEqual(
|
||||||
factory.getPage(1).children[1].children[0].attributes.style
|
pages.children[1].children[1].children[0].attributes.style
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user