From ca05b650aa5e62adc499e9357a0d434b1a1cf29a Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 26 Sep 2022 13:21:00 +0200 Subject: [PATCH 1/3] Remove the unused `rules` parameter from the `_prepareFontLoadEvent` method (PR 3477 follow-up) This is yet another small piece of functionality that became unused in PR 3477 (which landed nine years ago). --- src/display/font_loader.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/display/font_loader.js b/src/display/font_loader.js index ad8c5f23d..42f57a962 100644 --- a/src/display/font_loader.js +++ b/src/display/font_loader.js @@ -114,7 +114,7 @@ class FontLoader { } await new Promise(resolve => { const request = this._queueLoadingCallback(resolve); - this._prepareFontLoadEvent([rule], [font], request); + this._prepareFontLoadEvent([font], request); }); // The font was, asynchronously, loaded. } @@ -218,7 +218,7 @@ class FontLoader { return shadow(this, "_loadTestFont", testFont); } - _prepareFontLoadEvent(rules, fonts, request) { + _prepareFontLoadEvent(fonts, request) { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { throw new Error("Not implemented: _prepareFontLoadEvent"); } @@ -252,9 +252,8 @@ class FontLoader { let called = 0; function isFontReady(name, callback) { - called++; // With setTimeout clamping this gives the font ~100ms to load. - if (called > 30) { + if (++called > 30) { warn("Load test font never loaded."); callback(); return; From 2161f334a03806cfab0516f43c6b472945b2339f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 26 Sep 2022 13:25:26 +0200 Subject: [PATCH 2/3] Remove the ability to pass in more than one font to the `_prepareFontLoadEvent` method (PR 10539 follow-up) After the changes in PR 10539 (which landed over three years ago) the `FontLoader.bind` method can only be called with *a single* font at a time, hence the `_prepareFontLoadEvent` method obviously don't need to support multiple fonts any more. --- src/display/font_loader.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/display/font_loader.js b/src/display/font_loader.js index 42f57a962..84449e077 100644 --- a/src/display/font_loader.js +++ b/src/display/font_loader.js @@ -114,7 +114,7 @@ class FontLoader { } await new Promise(resolve => { const request = this._queueLoadingCallback(resolve); - this._prepareFontLoadEvent([font], request); + this._prepareFontLoadEvent(font, request); }); // The font was, asynchronously, loaded. } @@ -218,7 +218,7 @@ class FontLoader { return shadow(this, "_loadTestFont", testFont); } - _prepareFontLoadEvent(fonts, request) { + _prepareFontLoadEvent(font, request) { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { throw new Error("Not implemented: _prepareFontLoadEvent"); } @@ -299,19 +299,13 @@ class FontLoader { const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`; this.insertRule(rule); - const names = []; - for (const font of fonts) { - names.push(font.loadedName); - } - names.push(loadTestFontId); - const div = this._document.createElement("div"); div.style.visibility = "hidden"; div.style.width = div.style.height = "10px"; div.style.position = "absolute"; div.style.top = div.style.left = "0px"; - for (const name of names) { + for (const name of [font.loadedName, loadTestFontId]) { const span = this._document.createElement("span"); span.textContent = "Hi"; span.style.fontFamily = name; From 9ce2427e79cdcb070eab5aff5abe8fb34fd96961 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 26 Sep 2022 15:18:22 +0200 Subject: [PATCH 3/3] [Firefox viewer] Skip some unnecessary code in the `FontLoader.bind` method Given that Firefox supports *synchronous* font loading, when the Font Loading API isn't being used, there's really no point including code which if called would just throw in the MOZCENTRAL build. (This is safe, since the `FontLoader.isSyncFontLoadingSupported`-getter always return `true` there.) --- src/display/font_loader.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/display/font_loader.js b/src/display/font_loader.js index 84449e077..185e42585 100644 --- a/src/display/font_loader.js +++ b/src/display/font_loader.js @@ -112,6 +112,9 @@ class FontLoader { if (this.isSyncFontLoadingSupported) { return; // The font was, synchronously, loaded. } + if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { + throw new Error("Not implemented: async font loading"); + } await new Promise(resolve => { const request = this._queueLoadingCallback(resolve); this._prepareFontLoadEvent(font, request);