From 378caa72039667566cef5a0b7863c7dbfb882489 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 23 Mar 2023 14:02:02 +0100 Subject: [PATCH] Slightly reduce the size of the `FontInspector`-integration in the API Given that this functionality only applies in the viewer, when `PDFBug` is being enabled and used, it can't hurt to slightly reduce the size of this code. --- src/display/api.js | 14 +++++--------- src/display/font_loader.js | 8 ++++---- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 3abf43907..e206eed9b 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -2762,19 +2762,15 @@ class WorkerTransport { break; } - let fontRegistry = null; - if (params.pdfBug && globalThis.FontInspector?.enabled) { - fontRegistry = { - registerFont(font, url) { - globalThis.FontInspector.fontAdded(font, url); - }, - }; - } + const inspectFont = + params.pdfBug && globalThis.FontInspector?.enabled + ? (font, url) => globalThis.FontInspector.fontAdded(font, url) + : null; const font = new FontFaceObject(exportedData, { isEvalSupported: params.isEvalSupported, disableFontFace: params.disableFontFace, ignoreErrors: params.ignoreErrors, - fontRegistry, + inspectFont, }); this.fontLoader diff --git a/src/display/font_loader.js b/src/display/font_loader.js index b095fc8b2..cc29e7c45 100644 --- a/src/display/font_loader.js +++ b/src/display/font_loader.js @@ -322,7 +322,7 @@ class FontFaceObject { isEvalSupported = true, disableFontFace = false, ignoreErrors = false, - fontRegistry = null, + inspectFont = null, } ) { this.compiledGlyphs = Object.create(null); @@ -333,7 +333,7 @@ class FontFaceObject { this.isEvalSupported = isEvalSupported !== false; this.disableFontFace = disableFontFace === true; this.ignoreErrors = ignoreErrors === true; - this.fontRegistry = fontRegistry; + this._inspectFont = inspectFont; } createNativeFontFace() { @@ -357,7 +357,7 @@ class FontFaceObject { ); } - this.fontRegistry?.registerFont(this); + this._inspectFont?.(this); return nativeFontFace; } @@ -379,7 +379,7 @@ class FontFaceObject { rule = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${css}src:${url}}`; } - this.fontRegistry?.registerFont(this, url); + this._inspectFont?.(this, url); return rule; }