From a204f434f39ebabe82221cfcf280710180d9a03f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2024 21:28:02 +0100 Subject: [PATCH] Change `PDFPrintServiceFactory.createPrintService` to take a parameter object By "modernizing" the method to use a parameter object instead, we avoid having to pass along the needed parameters individually. --- web/app.js | 25 +++++++++---------------- web/firefox_print_service.js | 24 +++++------------------- web/pdf_print_service.js | 25 +++++-------------------- 3 files changed, 19 insertions(+), 55 deletions(-) diff --git a/web/app.js b/web/app.js index 64e3e86c2..7da0ffe52 100644 --- a/web/app.js +++ b/web/app.js @@ -1781,26 +1781,19 @@ const PDFViewerApplication = { return; } - const pagesOverview = this.pdfViewer.getPagesOverview(); - const printContainer = this.appConfig.printContainer; - const printResolution = AppOptions.get("printResolution"); - const optionalContentConfigPromise = - this.pdfViewer.optionalContentConfigPromise; - - const printService = PDFPrintServiceFactory.createPrintService( - this.pdfDocument, - pagesOverview, - printContainer, - printResolution, - optionalContentConfigPromise, - this._printAnnotationStoragePromise - ); - this.printService = printService; + this.printService = PDFPrintServiceFactory.createPrintService({ + pdfDocument: this.pdfDocument, + pagesOverview: this.pdfViewer.getPagesOverview(), + printContainer: this.appConfig.printContainer, + printResolution: AppOptions.get("printResolution"), + optionalContentConfigPromise: this.pdfViewer.optionalContentConfigPromise, + printAnnotationStoragePromise: this._printAnnotationStoragePromise, + }); this.forceRendering(); // Disable the editor-indicator during printing (fixes bug 1790552). this.setTitle(); - printService.layout(); + this.printService.layout(); if (this._hasAnnotationEditors) { this.externalServices.reportTelemetry({ diff --git a/web/firefox_print_service.js b/web/firefox_print_service.js index aa1428458..8241ed64d 100644 --- a/web/firefox_print_service.js +++ b/web/firefox_print_service.js @@ -114,14 +114,14 @@ function composePage( } class FirefoxPrintService { - constructor( + constructor({ pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, - printAnnotationStoragePromise = null - ) { + printAnnotationStoragePromise = null, + }) { this.pdfDocument = pdfDocument; this.pagesOverview = pagesOverview; this.printContainer = printContainer; @@ -202,22 +202,8 @@ class PDFPrintServiceFactory { return shadow(this, "supportsPrinting", "mozPrintCallback" in canvas); } - static createPrintService( - pdfDocument, - pagesOverview, - printContainer, - printResolution, - optionalContentConfigPromise, - printAnnotationStoragePromise - ) { - return new FirefoxPrintService( - pdfDocument, - pagesOverview, - printContainer, - printResolution, - optionalContentConfigPromise, - printAnnotationStoragePromise - ); + static createPrintService(params) { + return new FirefoxPrintService(params); } } diff --git a/web/pdf_print_service.js b/web/pdf_print_service.js index 2e2af18d2..cc4b330a6 100644 --- a/web/pdf_print_service.js +++ b/web/pdf_print_service.js @@ -63,14 +63,14 @@ function renderPage( } class PDFPrintService { - constructor( + constructor({ pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, - printAnnotationStoragePromise = null - ) { + printAnnotationStoragePromise = null, + }) { this.pdfDocument = pdfDocument; this.pagesOverview = pagesOverview; this.printContainer = printContainer; @@ -367,26 +367,11 @@ class PDFPrintServiceFactory { return shadow(this, "supportsPrinting", true); } - static createPrintService( - pdfDocument, - pagesOverview, - printContainer, - printResolution, - optionalContentConfigPromise, - printAnnotationStoragePromise - ) { + static createPrintService(params) { if (activeService) { throw new Error("The print service is created and active."); } - activeService = new PDFPrintService( - pdfDocument, - pagesOverview, - printContainer, - printResolution, - optionalContentConfigPromise, - printAnnotationStoragePromise - ); - return activeService; + return (activeService = new PDFPrintService(params)); } }