mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-02-08 00:21:11 +01:00
Replace the IPDFPrintServiceFactory interface with an abstract BasePrintServiceFactory class
This should help reduce the maintenance burden of the code, since you no longer need to remember to update separate code when touching the different `PDFPrintServiceFactory` classes.
This commit is contained in:
parent
50a12e3e67
commit
ff7f87fc21
@ -2456,10 +2456,7 @@ const PDFViewerApplication = {
|
||||
};
|
||||
|
||||
initCom(PDFViewerApplication);
|
||||
|
||||
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
||||
PDFPrintServiceFactory.initGlobals(PDFViewerApplication);
|
||||
}
|
||||
PDFPrintServiceFactory.initGlobals(PDFViewerApplication);
|
||||
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
const HOSTED_VIEWER_ORIGINS = new Set([
|
||||
|
||||
@ -19,7 +19,10 @@ import {
|
||||
RenderingCancelledException,
|
||||
shadow,
|
||||
} from "pdfjs-lib";
|
||||
import { getXfaHtmlForPrinting } from "./print_utils.js";
|
||||
import {
|
||||
BasePrintServiceFactory,
|
||||
getXfaHtmlForPrinting,
|
||||
} from "./print_utils.js";
|
||||
|
||||
// Creates a placeholder with div and canvas with right size for the page.
|
||||
function composePage(
|
||||
@ -194,10 +197,7 @@ class FirefoxPrintService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @implements {IPDFPrintServiceFactory}
|
||||
*/
|
||||
class PDFPrintServiceFactory {
|
||||
class PDFPrintServiceFactory extends BasePrintServiceFactory {
|
||||
static get supportsPrinting() {
|
||||
const canvas = document.createElement("canvas");
|
||||
return shadow(this, "supportsPrinting", "mozPrintCallback" in canvas);
|
||||
|
||||
@ -71,19 +71,4 @@ class IDownloadManager {
|
||||
download(data, url, filename) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
class IPDFPrintServiceFactory {
|
||||
static initGlobals() {}
|
||||
|
||||
static get supportsPrinting() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static createPrintService() {
|
||||
throw new Error("Not implemented: createPrintService");
|
||||
}
|
||||
}
|
||||
|
||||
export { IDownloadManager, IPDFPrintServiceFactory, IRenderableView };
|
||||
export { IDownloadManager, IRenderableView };
|
||||
|
||||
@ -13,16 +13,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
/** @typedef {import("./interfaces.js").IPDFPrintServiceFactory} IPDFPrintServiceFactory */
|
||||
|
||||
import {
|
||||
AnnotationMode,
|
||||
PixelsPerInch,
|
||||
RenderingCancelledException,
|
||||
shadow,
|
||||
} from "pdfjs-lib";
|
||||
import { getXfaHtmlForPrinting } from "./print_utils.js";
|
||||
import {
|
||||
BasePrintServiceFactory,
|
||||
getXfaHtmlForPrinting,
|
||||
} from "./print_utils.js";
|
||||
|
||||
let activeService = null;
|
||||
let dialog = null;
|
||||
@ -371,10 +371,7 @@ function ensureOverlay() {
|
||||
return overlayPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @implements {IPDFPrintServiceFactory}
|
||||
*/
|
||||
class PDFPrintServiceFactory {
|
||||
class PDFPrintServiceFactory extends BasePrintServiceFactory {
|
||||
static initGlobals(app) {
|
||||
viewerApp = app;
|
||||
}
|
||||
|
||||
@ -17,6 +17,24 @@ import { getXfaPageViewport, PixelsPerInch } from "pdfjs-lib";
|
||||
import { SimpleLinkService } from "./pdf_link_service.js";
|
||||
import { XfaLayerBuilder } from "./xfa_layer_builder.js";
|
||||
|
||||
class BasePrintServiceFactory {
|
||||
constructor() {
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||
throw new Error("Cannot initialize BasePrintServiceFactory.");
|
||||
}
|
||||
}
|
||||
|
||||
static initGlobals(app) {}
|
||||
|
||||
static get supportsPrinting() {
|
||||
throw new Error("Not implemented: supportsPrinting");
|
||||
}
|
||||
|
||||
static createPrintService(params) {
|
||||
throw new Error("Not implemented: createPrintService");
|
||||
}
|
||||
}
|
||||
|
||||
function getXfaHtmlForPrinting(printContainer, pdfDocument) {
|
||||
const xfaHtml = pdfDocument.allXfaHtml;
|
||||
const linkService = new SimpleLinkService();
|
||||
@ -40,4 +58,4 @@ function getXfaHtmlForPrinting(printContainer, pdfDocument) {
|
||||
}
|
||||
}
|
||||
|
||||
export { getXfaHtmlForPrinting };
|
||||
export { BasePrintServiceFactory, getXfaHtmlForPrinting };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user