mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-03 04:47:21 +02:00
Compare commits
6 Commits
f8c2a949b7
...
e738566900
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e738566900 | ||
|
|
f44cba86d5 | ||
|
|
4c5ad92584 | ||
|
|
e3e2396230 | ||
|
|
d86045eacb | ||
|
|
9e8d4e4d46 |
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"stableVersion": "5.0.375",
|
"stableVersion": "5.0.375",
|
||||||
"baseVersion": "7a57af12e13a47927c460e6b739a6ca132e7603d",
|
"baseVersion": "d86045eacbd6f8cc9cbe8fd616800ca3edcbd0dc",
|
||||||
"versionPrefix": "5.0."
|
"versionPrefix": "5.1."
|
||||||
}
|
}
|
||||||
|
|||||||
@ -289,7 +289,7 @@ class ColorSpaceUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static get cmyk() {
|
static get cmyk() {
|
||||||
if (IccColorSpace.isUsable) {
|
if (CmykICCBasedCS.isUsable) {
|
||||||
try {
|
try {
|
||||||
return shadow(this, "cmyk", new CmykICCBasedCS());
|
return shadow(this, "cmyk", new CmykICCBasedCS());
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@ -130,11 +130,15 @@ class IccColorSpace extends ColorSpace {
|
|||||||
static get isUsable() {
|
static get isUsable() {
|
||||||
let isUsable = false;
|
let isUsable = false;
|
||||||
if (this.#useWasm) {
|
if (this.#useWasm) {
|
||||||
try {
|
if (this.#wasmUrl) {
|
||||||
this._module = QCMS._module = this.#load();
|
try {
|
||||||
isUsable = !!this._module;
|
this._module = QCMS._module = this.#load();
|
||||||
} catch (e) {
|
isUsable = !!this._module;
|
||||||
warn(`ICCBased color space: "${e}".`);
|
} catch (e) {
|
||||||
|
warn(`ICCBased color space: "${e}".`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn("No ICC color space support due to missing `wasmUrl` API option");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,6 +173,19 @@ class CmykICCBasedCS extends IccColorSpace {
|
|||||||
static setOptions({ iccUrl }) {
|
static setOptions({ iccUrl }) {
|
||||||
this.#iccUrl = iccUrl;
|
this.#iccUrl = iccUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get isUsable() {
|
||||||
|
let isUsable = false;
|
||||||
|
if (IccColorSpace.isUsable) {
|
||||||
|
if (this.#iccUrl) {
|
||||||
|
isUsable = true;
|
||||||
|
} else {
|
||||||
|
warn("No CMYK ICC profile support due to missing `iccUrl` API option");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return shadow(this, "isUsable", isUsable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { CmykICCBasedCS, IccColorSpace };
|
export { CmykICCBasedCS, IccColorSpace };
|
||||||
|
|||||||
@ -629,39 +629,48 @@ const isValidExplicitDest = _isValidExplicitDest.bind(
|
|||||||
class PDFDocumentLoadingTask {
|
class PDFDocumentLoadingTask {
|
||||||
static #docId = 0;
|
static #docId = 0;
|
||||||
|
|
||||||
constructor() {
|
/**
|
||||||
this._capability = Promise.withResolvers();
|
* @private
|
||||||
this._transport = null;
|
*/
|
||||||
this._worker = null;
|
_capability = Promise.withResolvers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique identifier for the document loading task.
|
* @private
|
||||||
* @type {string}
|
*/
|
||||||
*/
|
_transport = null;
|
||||||
this.docId = `d${PDFDocumentLoadingTask.#docId++}`;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the loading task is destroyed or not.
|
* @private
|
||||||
* @type {boolean}
|
*/
|
||||||
*/
|
_worker = null;
|
||||||
this.destroyed = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback to request a password if a wrong or no password was provided.
|
* Unique identifier for the document loading task.
|
||||||
* The callback receives two parameters: a function that should be called
|
* @type {string}
|
||||||
* with the new password, and a reason (see {@link PasswordResponses}).
|
*/
|
||||||
* @type {function}
|
docId = `d${PDFDocumentLoadingTask.#docId++}`;
|
||||||
*/
|
|
||||||
this.onPassword = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback to be able to monitor the loading progress of the PDF file
|
* Whether the loading task is destroyed or not.
|
||||||
* (necessary to implement e.g. a loading bar).
|
* @type {boolean}
|
||||||
* The callback receives an {@link OnProgressParameters} argument.
|
*/
|
||||||
* @type {function}
|
destroyed = false;
|
||||||
*/
|
|
||||||
this.onProgress = null;
|
/**
|
||||||
}
|
* Callback to request a password if a wrong or no password was provided.
|
||||||
|
* The callback receives two parameters: a function that should be called
|
||||||
|
* with the new password, and a reason (see {@link PasswordResponses}).
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
|
onPassword = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback to be able to monitor the loading progress of the PDF file
|
||||||
|
* (necessary to implement e.g. a loading bar).
|
||||||
|
* The callback receives an {@link OnProgressParameters} argument.
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
|
onProgress = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promise for document loading task completion.
|
* Promise for document loading task completion.
|
||||||
@ -699,6 +708,16 @@ class PDFDocumentLoadingTask {
|
|||||||
this._worker?.destroy();
|
this._worker?.destroy();
|
||||||
this._worker = null;
|
this._worker = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to fetch the raw data of the PDF document, when e.g.
|
||||||
|
* - An exception was thrown during document initialization.
|
||||||
|
* - An `onPassword` callback is delaying initialization.
|
||||||
|
* @returns {Promise<Uint8Array>}
|
||||||
|
*/
|
||||||
|
async getData() {
|
||||||
|
return this._transport.getData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -828,6 +828,47 @@ describe("api", function () {
|
|||||||
|
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("gets data, on failure, from `PDFDocumentLoadingTask`-instance", async function () {
|
||||||
|
const typedArrayPdf = await DefaultFileReaderFactory.fetch({
|
||||||
|
path: TEST_PDFS_PATH + "issue6010_1.pdf",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sanity check to make sure that we fetched the entire PDF file.
|
||||||
|
expect(typedArrayPdf instanceof Uint8Array).toEqual(true);
|
||||||
|
expect(typedArrayPdf.length).toEqual(1116);
|
||||||
|
|
||||||
|
const loadingTask = getDocument(typedArrayPdf.slice());
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
|
|
||||||
|
let passwordData = null;
|
||||||
|
// Attach the callback that is used to request a password;
|
||||||
|
// similarly to how the default viewer handles passwords.
|
||||||
|
loadingTask.onPassword = async (updatePassword, reason) => {
|
||||||
|
passwordData = await loadingTask.getData();
|
||||||
|
|
||||||
|
updatePassword(new Error("Should reject the loadingTask."));
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await loadingTask.promise;
|
||||||
|
|
||||||
|
// Shouldn't get here.
|
||||||
|
expect(false).toEqual(true);
|
||||||
|
} catch (ex) {
|
||||||
|
expect(ex instanceof PasswordException).toEqual(true);
|
||||||
|
expect(ex.code).toEqual(PasswordResponses.NEED_PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that the raw PDF document can be fetched while
|
||||||
|
// an `onPassword` callback is delaying initialization...
|
||||||
|
expect(passwordData).toEqual(typedArrayPdf);
|
||||||
|
// ... and once an exception has stopped initialization.
|
||||||
|
const data = await loadingTask.getData();
|
||||||
|
expect(data).toEqual(typedArrayPdf);
|
||||||
|
|
||||||
|
await loadingTask.destroy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("PDFWorker", function () {
|
describe("PDFWorker", function () {
|
||||||
|
|||||||
@ -1153,7 +1153,9 @@ const PDFViewerApplication = {
|
|||||||
async download() {
|
async download() {
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
data = await this.pdfDocument.getData();
|
data = await (this.pdfDocument
|
||||||
|
? this.pdfDocument.getData()
|
||||||
|
: this.pdfLoadingTask.getData());
|
||||||
} catch {
|
} catch {
|
||||||
// When the PDF document isn't ready, simply download using the URL.
|
// When the PDF document isn't ready, simply download using the URL.
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user