Convert FirefoxPrintService and PDFPrintService into standard classes

Note that both of the affected files are old enough to predate the general availability of `class`.
This commit is contained in:
Jonas Jenwald 2023-04-14 09:51:37 +02:00
parent ebf493f726
commit aeb8e36cdb
2 changed files with 52 additions and 52 deletions

View File

@ -114,25 +114,25 @@ function composePage(
}; };
} }
function FirefoxPrintService( class FirefoxPrintService {
pdfDocument, constructor(
pagesOverview, pdfDocument,
printContainer, pagesOverview,
printResolution, printContainer,
optionalContentConfigPromise = null, printResolution,
printAnnotationStoragePromise = null optionalContentConfigPromise = null,
) { printAnnotationStoragePromise = null
this.pdfDocument = pdfDocument; ) {
this.pagesOverview = pagesOverview; this.pdfDocument = pdfDocument;
this.printContainer = printContainer; this.pagesOverview = pagesOverview;
this._printResolution = printResolution || 150; this.printContainer = printContainer;
this._optionalContentConfigPromise = this._printResolution = printResolution || 150;
optionalContentConfigPromise || pdfDocument.getOptionalContentConfig(); this._optionalContentConfigPromise =
this._printAnnotationStoragePromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
printAnnotationStoragePromise || Promise.resolve(); this._printAnnotationStoragePromise =
} printAnnotationStoragePromise || Promise.resolve();
}
FirefoxPrintService.prototype = {
layout() { layout() {
const { const {
pdfDocument, pdfDocument,
@ -179,7 +179,7 @@ FirefoxPrintService.prototype = {
_printAnnotationStoragePromise _printAnnotationStoragePromise
); );
} }
}, }
destroy() { destroy() {
this.printContainer.textContent = ""; this.printContainer.textContent = "";
@ -191,8 +191,8 @@ FirefoxPrintService.prototype = {
this.pageStyleSheet.remove(); this.pageStyleSheet.remove();
this.pageStyleSheet = null; this.pageStyleSheet = null;
} }
}, }
}; }
PDFPrintServiceFactory.instance = { PDFPrintServiceFactory.instance = {
get supportsPrinting() { get supportsPrinting() {

View File

@ -62,30 +62,30 @@ function renderPage(
}); });
} }
function PDFPrintService( class PDFPrintService {
pdfDocument, constructor(
pagesOverview, pdfDocument,
printContainer, pagesOverview,
printResolution, printContainer,
optionalContentConfigPromise = null, printResolution,
printAnnotationStoragePromise = null, optionalContentConfigPromise = null,
l10n printAnnotationStoragePromise = null,
) { l10n
this.pdfDocument = pdfDocument; ) {
this.pagesOverview = pagesOverview; this.pdfDocument = pdfDocument;
this.printContainer = printContainer; this.pagesOverview = pagesOverview;
this._printResolution = printResolution || 150; this.printContainer = printContainer;
this._optionalContentConfigPromise = this._printResolution = printResolution || 150;
optionalContentConfigPromise || pdfDocument.getOptionalContentConfig(); this._optionalContentConfigPromise =
this._printAnnotationStoragePromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
printAnnotationStoragePromise || Promise.resolve(); this._printAnnotationStoragePromise =
this.l10n = l10n; printAnnotationStoragePromise || Promise.resolve();
this.currentPage = -1; this.l10n = l10n;
// The temporary canvas where renderPage paints one page at a time. this.currentPage = -1;
this.scratchCanvas = document.createElement("canvas"); // The temporary canvas where renderPage paints one page at a time.
} this.scratchCanvas = document.createElement("canvas");
}
PDFPrintService.prototype = {
layout() { layout() {
this.throwIfInactive(); this.throwIfInactive();
@ -114,7 +114,7 @@ PDFPrintService.prototype = {
this.pageStyleSheet = document.createElement("style"); this.pageStyleSheet = document.createElement("style");
this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`; this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`;
body.append(this.pageStyleSheet); body.append(this.pageStyleSheet);
}, }
destroy() { destroy() {
if (activeService !== this) { if (activeService !== this) {
@ -139,7 +139,7 @@ PDFPrintService.prototype = {
overlayManager.close(dialog); overlayManager.close(dialog);
} }
}); });
}, }
renderPages() { renderPages() {
if (this.pdfDocument.isPureXfa) { if (this.pdfDocument.isPureXfa) {
@ -172,7 +172,7 @@ PDFPrintService.prototype = {
}, reject); }, reject);
}; };
return new Promise(renderNextPage); return new Promise(renderNextPage);
}, }
useRenderedPage() { useRenderedPage() {
this.throwIfInactive(); this.throwIfInactive();
@ -195,7 +195,7 @@ PDFPrintService.prototype = {
img.onload = resolve; img.onload = resolve;
img.onerror = reject; img.onerror = reject;
}); });
}, }
performPrint() { performPrint() {
this.throwIfInactive(); this.throwIfInactive();
@ -213,18 +213,18 @@ PDFPrintService.prototype = {
setTimeout(resolve, 20); // Tidy-up. setTimeout(resolve, 20); // Tidy-up.
}, 0); }, 0);
}); });
}, }
get active() { get active() {
return this === activeService; return this === activeService;
}, }
throwIfInactive() { throwIfInactive() {
if (!this.active) { if (!this.active) {
throw new Error("This print request was cancelled or completed."); throw new Error("This print request was cancelled or completed.");
} }
}, }
}; }
const print = window.print; const print = window.print;
window.print = function () { window.print = function () {