Skip to content

Commit ff7f87f

Browse files
committed
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.
1 parent 50a12e3 commit ff7f87f

5 files changed

Lines changed: 31 additions & 34 deletions

File tree

web/app.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,10 +2456,7 @@ const PDFViewerApplication = {
24562456
};
24572457

24582458
initCom(PDFViewerApplication);
2459-
2460-
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
2461-
PDFPrintServiceFactory.initGlobals(PDFViewerApplication);
2462-
}
2459+
PDFPrintServiceFactory.initGlobals(PDFViewerApplication);
24632460

24642461
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
24652462
const HOSTED_VIEWER_ORIGINS = new Set([

web/firefox_print_service.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import {
1919
RenderingCancelledException,
2020
shadow,
2121
} from "pdfjs-lib";
22-
import { getXfaHtmlForPrinting } from "./print_utils.js";
22+
import {
23+
BasePrintServiceFactory,
24+
getXfaHtmlForPrinting,
25+
} from "./print_utils.js";
2326

2427
// Creates a placeholder with div and canvas with right size for the page.
2528
function composePage(
@@ -194,10 +197,7 @@ class FirefoxPrintService {
194197
}
195198
}
196199

197-
/**
198-
* @implements {IPDFPrintServiceFactory}
199-
*/
200-
class PDFPrintServiceFactory {
200+
class PDFPrintServiceFactory extends BasePrintServiceFactory {
201201
static get supportsPrinting() {
202202
const canvas = document.createElement("canvas");
203203
return shadow(this, "supportsPrinting", "mozPrintCallback" in canvas);

web/interfaces.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,4 @@ class IDownloadManager {
7171
download(data, url, filename) {}
7272
}
7373

74-
/**
75-
* @interface
76-
*/
77-
class IPDFPrintServiceFactory {
78-
static initGlobals() {}
79-
80-
static get supportsPrinting() {
81-
return false;
82-
}
83-
84-
static createPrintService() {
85-
throw new Error("Not implemented: createPrintService");
86-
}
87-
}
88-
89-
export { IDownloadManager, IPDFPrintServiceFactory, IRenderableView };
74+
export { IDownloadManager, IRenderableView };

web/pdf_print_service.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
* limitations under the License.
1414
*/
1515

16-
// eslint-disable-next-line max-len
17-
/** @typedef {import("./interfaces.js").IPDFPrintServiceFactory} IPDFPrintServiceFactory */
18-
1916
import {
2017
AnnotationMode,
2118
PixelsPerInch,
2219
RenderingCancelledException,
2320
shadow,
2421
} from "pdfjs-lib";
25-
import { getXfaHtmlForPrinting } from "./print_utils.js";
22+
import {
23+
BasePrintServiceFactory,
24+
getXfaHtmlForPrinting,
25+
} from "./print_utils.js";
2626

2727
let activeService = null;
2828
let dialog = null;
@@ -371,10 +371,7 @@ function ensureOverlay() {
371371
return overlayPromise;
372372
}
373373

374-
/**
375-
* @implements {IPDFPrintServiceFactory}
376-
*/
377-
class PDFPrintServiceFactory {
374+
class PDFPrintServiceFactory extends BasePrintServiceFactory {
378375
static initGlobals(app) {
379376
viewerApp = app;
380377
}

web/print_utils.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ import { getXfaPageViewport, PixelsPerInch } from "pdfjs-lib";
1717
import { SimpleLinkService } from "./pdf_link_service.js";
1818
import { XfaLayerBuilder } from "./xfa_layer_builder.js";
1919

20+
class BasePrintServiceFactory {
21+
constructor() {
22+
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
23+
throw new Error("Cannot initialize BasePrintServiceFactory.");
24+
}
25+
}
26+
27+
static initGlobals(app) {}
28+
29+
static get supportsPrinting() {
30+
throw new Error("Not implemented: supportsPrinting");
31+
}
32+
33+
static createPrintService(params) {
34+
throw new Error("Not implemented: createPrintService");
35+
}
36+
}
37+
2038
function getXfaHtmlForPrinting(printContainer, pdfDocument) {
2139
const xfaHtml = pdfDocument.allXfaHtml;
2240
const linkService = new SimpleLinkService();
@@ -40,4 +58,4 @@ function getXfaHtmlForPrinting(printContainer, pdfDocument) {
4058
}
4159
}
4260

43-
export { getXfaHtmlForPrinting };
61+
export { BasePrintServiceFactory, getXfaHtmlForPrinting };

0 commit comments

Comments
 (0)