From 90bf659b29f22e9854ef795c1ba5fbc97c9667df Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 16 Jul 2022 10:24:24 +0200 Subject: [PATCH 1/2] [api-minor] Deprecate the SVG back-end --- src/display/svg.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/display/svg.js b/src/display/svg.js index a0e9813e9..e24f47332 100644 --- a/src/display/svg.js +++ b/src/display/svg.js @@ -14,6 +14,7 @@ */ /* globals __non_webpack_require__ */ +import { deprecated, DOMSVGFactory } from "./display_utils.js"; import { FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, @@ -24,7 +25,6 @@ import { Util, warn, } from "../shared/util.js"; -import { DOMSVGFactory } from "./display_utils.js"; import { isNodeJS } from "../shared/is_node.js"; /** @type {any} */ @@ -467,6 +467,9 @@ if ( SVGGraphics = class { constructor(commonObjs, objs, forceDataSchema = false) { + deprecated( + "The SVG back-end is no longer maintained and *may* be removed in the future." + ); this.svgFactory = new DOMSVGFactory(); this.current = new SVGExtraState(); From 290aeaf755ed1d4c9cf04ae2616ed894241e8f67 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 16 Jul 2022 10:31:25 +0200 Subject: [PATCH 2/2] Limit more SVG-specific code to the GENERIC viewer Given that the SVG back-end is not defined anywhere except in GENERIC builds, we can remove a little bit more unnecessary code in e.g. the Firefox PDF Viewer. --- web/app.js | 15 +++++++++++---- web/pdf_page_view.js | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/web/app.js b/web/app.js index 5ebe75555..8b4e6265e 100644 --- a/web/app.js +++ b/web/app.js @@ -1795,10 +1795,17 @@ const PDFViewerApplication = { this.pdfViewer.cleanup(); this.pdfThumbnailViewer.cleanup(); - // We don't want to remove fonts used by active page SVGs. - this.pdfDocument.cleanup( - /* keepLoadedFonts = */ this.pdfViewer.renderer === RendererType.SVG - ); + if ( + typeof PDFJSDev === "undefined" || + PDFJSDev.test("!PRODUCTION || GENERIC") + ) { + // We don't want to remove fonts used by active page SVGs. + this.pdfDocument.cleanup( + /* keepLoadedFonts = */ this.pdfViewer.renderer === RendererType.SVG + ); + } else { + this.pdfDocument.cleanup(); + } }, forceRendering() { diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 8b7776450..82d0bbf9e 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -344,7 +344,11 @@ class PDFPageView { } this._resetZoomLayer(); } - if (this.svg) { + if ( + (typeof PDFJSDev === "undefined" || + PDFJSDev.test("!PRODUCTION || GENERIC")) && + this.svg + ) { this.paintedViewportMap.delete(this.svg); delete this.svg; } @@ -380,7 +384,11 @@ class PDFPageView { docStyle.setProperty("--scale-factor", this.viewport.scale); } - if (this.svg) { + if ( + (typeof PDFJSDev === "undefined" || + PDFJSDev.test("!PRODUCTION || GENERIC")) && + this.svg + ) { this.cssTransform({ target: this.svg, redrawAnnotationLayer: true, @@ -733,6 +741,8 @@ class PDFPageView { }; const paintTask = + (typeof PDFJSDev === "undefined" || + PDFJSDev.test("!PRODUCTION || GENERIC")) && this.renderer === RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);