From 85f03c0ea447b1c4a4564d086f96c1efea0963fd Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 27 Nov 2022 12:19:11 +0100 Subject: [PATCH] Slightly modernize the `FontLoader.isSyncFontLoadingSupported` getter This is very old code, which is unused (by default) in browsers nowadays since the Font Loading API will always be preferred. For Node.js environments we use the same constant as elsewhere throughout the code-base, and we can also simplify the Firefox-specific check given that the lowest supported version is `102` (as of this writing). Finally the old TODO is removed, since the general availability of the Font Loading API has made it redundant. --- src/display/font_loader.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/display/font_loader.js b/src/display/font_loader.js index 5cb508da721a9..244ce9ca99fcf 100644 --- a/src/display/font_loader.js +++ b/src/display/font_loader.js @@ -22,6 +22,7 @@ import { UNSUPPORTED_FEATURES, warn, } from "../shared/util.js"; +import { isNodeJS } from "../shared/is_node.js"; class FontLoader { constructor({ @@ -141,17 +142,17 @@ class FontLoader { let supported = false; if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME")) { - if (typeof navigator === "undefined") { + if (isNodeJS) { // Node.js - we can pretend that sync font loading is supported. supported = true; - } else { + } else if ( + typeof navigator !== "undefined" && // User agent string sniffing is bad, but there is no reliable way to // tell if the font is fully loaded and ready to be used with canvas. - const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent); - if (m?.[1] >= 14) { - supported = true; - } - // TODO - other browsers... + /Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent) + ) { + // Firefox, from version 14, supports synchronous font loading. + supported = true; } } return shadow(this, "isSyncFontLoadingSupported", supported);