mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 01:35:43 +02:00
Improve the loadingParams
functionality in the API
- Move the definition of the `loadingParams` Object, to simplify the code. - Add a unit-test, since none existed and the viewer depends on this functionality.
This commit is contained in:
parent
08bf96865d
commit
06334c97ef
2 changed files with 22 additions and 10 deletions
|
@ -386,11 +386,13 @@ function getDocument(src) {
|
||||||
const transportParams = {
|
const transportParams = {
|
||||||
disableFontFace,
|
disableFontFace,
|
||||||
fontExtraProperties,
|
fontExtraProperties,
|
||||||
enableXfa,
|
|
||||||
ownerDocument,
|
ownerDocument,
|
||||||
disableAutoFetch,
|
|
||||||
pdfBug,
|
pdfBug,
|
||||||
styleElement,
|
styleElement,
|
||||||
|
loadingParams: {
|
||||||
|
disableAutoFetch,
|
||||||
|
enableXfa,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
worker.promise
|
worker.promise
|
||||||
|
@ -2364,6 +2366,7 @@ class WorkerTransport {
|
||||||
ownerDocument: params.ownerDocument,
|
ownerDocument: params.ownerDocument,
|
||||||
styleElement: params.styleElement,
|
styleElement: params.styleElement,
|
||||||
});
|
});
|
||||||
|
this.loadingParams = params.loadingParams;
|
||||||
this._params = params;
|
this._params = params;
|
||||||
|
|
||||||
this.canvasFactory = factory.canvasFactory;
|
this.canvasFactory = factory.canvasFactory;
|
||||||
|
@ -3095,14 +3098,6 @@ class WorkerTransport {
|
||||||
const refStr = ref.gen === 0 ? `${ref.num}R` : `${ref.num}R${ref.gen}`;
|
const refStr = ref.gen === 0 ? `${ref.num}R` : `${ref.num}R${ref.gen}`;
|
||||||
return this.#pageRefCache.get(refStr) ?? null;
|
return this.#pageRefCache.get(refStr) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get loadingParams() {
|
|
||||||
const { disableAutoFetch, enableXfa } = this._params;
|
|
||||||
return shadow(this, "loadingParams", {
|
|
||||||
disableAutoFetch,
|
|
||||||
enableXfa,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const INITIAL_DATA = Symbol("INITIAL_DATA");
|
const INITIAL_DATA = Symbol("INITIAL_DATA");
|
||||||
|
|
|
@ -1069,6 +1069,23 @@ describe("api", function () {
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("gets loadingParams", async function () {
|
||||||
|
const loadingTask = getDocument(
|
||||||
|
buildGetDocumentParams(basicApiFileName, {
|
||||||
|
disableAutoFetch: true,
|
||||||
|
enableXfa: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const pdfDoc = await loadingTask.promise;
|
||||||
|
|
||||||
|
expect(pdfDoc.loadingParams).toEqual({
|
||||||
|
disableAutoFetch: true,
|
||||||
|
enableXfa: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
await loadingTask.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
it("gets page", async function () {
|
it("gets page", async function () {
|
||||||
const data = await pdfDocument.getPage(1);
|
const data = await pdfDocument.getPage(1);
|
||||||
expect(data instanceof PDFPageProxy).toEqual(true);
|
expect(data instanceof PDFPageProxy).toEqual(true);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue