1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

XFA - Move the fake HTML representation of XFA from the worker to the main thread

- the only goal of this patch is to be able to get synchronously the fake html when printing from firefox:
    - in order to print we need to inject some html in beforeprint callback but we cannot block in waiting for all the pages.
  - from a memory point of view: it doesn't change anything since the fake HTML is deleted in the worker;
  - this way we don't break any assumptions.
This commit is contained in:
Calixte Denizet 2021-05-25 15:50:12 +02:00
parent 9478d2f064
commit 45c3f00a27
5 changed files with 50 additions and 32 deletions

View file

@ -146,8 +146,7 @@ class Page {
_getBoundingBox(name) {
if (this.xfaData) {
const { width, height } = this.xfaData.attributes.style;
return [0, 0, parseInt(width), parseInt(height)];
return this.xfaData.bbox;
}
const box = this._getInheritableProperty(name, /* getArray = */ true);
@ -241,7 +240,9 @@ class Page {
get xfaData() {
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);
}
@ -851,8 +852,11 @@ class PDFDocument {
return shadow(this, "xfaFaxtory", null);
}
get isPureXfa() {
return this.xfaFactory !== null;
get htmlForXfa() {
if (this.xfaFactory) {
return this.xfaFactory.getPages();
}
return null;
}
async loadXfaFonts(handler, task) {

View file

@ -187,13 +187,13 @@ class WorkerMessageHandler {
await pdfManager.ensureDoc("checkFirstPage");
}
const [numPages, fingerprint, isPureXfa] = await Promise.all([
const [numPages, fingerprint, htmlForXfa] = await Promise.all([
pdfManager.ensureDoc("numPages"),
pdfManager.ensureDoc("fingerprint"),
pdfManager.ensureDoc("isPureXfa"),
pdfManager.ensureDoc("htmlForXfa"),
]);
if (isPureXfa) {
if (htmlForXfa) {
const task = new WorkerTask("loadXfaFonts");
startWorkerTask(task);
await pdfManager
@ -203,7 +203,7 @@ class WorkerMessageHandler {
})
.then(() => finishWorkerTask(task));
}
return { numPages, fingerprint, isPureXfa };
return { numPages, fingerprint, htmlForXfa };
}
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) {
return pdfManager.ensureCatalog("documentOutline");
});

View file

@ -22,18 +22,35 @@ class XFAFactory {
try {
this.root = new XFAParser().parse(XFAFactory._createDocument(data));
this.form = new Binder(this.root).bind();
this.pages = this.form[$toHTML]();
this._createPages();
} catch (e) {
console.log(e);
}
}
getPage(pageIndex) {
return this.pages.children[pageIndex];
_createPages() {
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() {
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) {