diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 4baf3ffe2759aa..2ed7a82e4d23b1 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -4197,15 +4197,15 @@ class PartialEvaluator { if (standardFontName) { file = await this.fetchStandardFontData(standardFontName); properties.isInternalFont = !!file; - if (!properties.isInternalFont && this.options.useSystemFonts) { - properties.systemFontInfo = getFontSubstitution( - this.systemFontCache, - this.idFactory, - this.options.standardFontDataUrl, - baseFontName, - standardFontName - ); - } + } + if (!properties.isInternalFont && this.options.useSystemFonts) { + properties.systemFontInfo = getFontSubstitution( + this.systemFontCache, + this.idFactory, + this.options.standardFontDataUrl, + baseFontName, + standardFontName + ); } return this.extractDataStructures(dict, dict, properties).then( newProperties => { @@ -4310,15 +4310,15 @@ class PartialEvaluator { if (standardFontName) { fontFile = await this.fetchStandardFontData(standardFontName); isInternalFont = !!fontFile; - if (!isInternalFont && this.options.useSystemFonts) { - systemFontInfo = getFontSubstitution( - this.systemFontCache, - this.idFactory, - this.options.standardFontDataUrl, - fontName.name, - standardFontName - ); - } + } + if (!isInternalFont && this.options.useSystemFonts) { + systemFontInfo = getFontSubstitution( + this.systemFontCache, + this.idFactory, + this.options.standardFontDataUrl, + fontName.name, + standardFontName + ); } } diff --git a/src/core/font_substitutions.js b/src/core/font_substitutions.js index bc576aa6d1fd3b..3c6043f4710318 100644 --- a/src/core/font_substitutions.js +++ b/src/core/font_substitutions.js @@ -378,8 +378,8 @@ function makeLocal(prepend, local) { * @param {Object} idFactory The ids factory. * @param {String} localFontPath Path to the fonts directory. * @param {String} baseFontName The font name to be substituted. - * @param {String} standardFontName The standard font name to use if the base - * font is not available. + * @param {String|undefined} standardFontName The standard font name to use + * if the base font is not available. * @returns an Object with the CSS, the loaded name, the src and the style. */ function getFontSubstitution( @@ -437,7 +437,8 @@ function getFontSubstitution( (italic && ITALIC) || NORMAL; substitutionInfo = { - css: `${loadedName},sans-serif`, + css: loadedName, + mustGuessFallback: true, loadedName, src: `local(${baseFontName})`, style, diff --git a/src/core/fonts.js b/src/core/fonts.js index 62502cfa1e0930..7849d69d5af98e 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -986,6 +986,7 @@ class Font { let { type, subtype } = properties; this.type = type; this.subtype = subtype; + this.systemFontInfo = properties.systemFontInfo; const matches = name.match(/^InvalidPDFjsFont_(.*)_\d+$/); this.isInvalidPDFjsFont = !!matches; @@ -999,7 +1000,10 @@ class Font { this.fallbackName = "sans-serif"; } - this.systemFontInfo = properties.systemFontInfo; + if (this.systemFontInfo?.mustGuessFallback) { + this.systemFontInfo.css = `${this.systemFontInfo.css},${this.fallbackName}`; + } + this.differences = properties.differences; this.widths = properties.widths; this.defaultWidth = properties.defaultWidth; diff --git a/src/display/font_loader.js b/src/display/font_loader.js index dce51fafb3b6bf..d698008361e30e 100644 --- a/src/display/font_loader.js +++ b/src/display/font_loader.js @@ -97,9 +97,17 @@ class FontLoader { await fontFace.load(); this.#systemFonts.add(loadedName); } catch { - warn( - `Cannot load system font: ${loadedName} for style ${style.style} and weight ${style.weight}.` - ); + if (info.mustGuessFallback) { + // We're trying to load only one system font. + const match = src.match(/^local\((.*)\)$/); + warn( + `Cannot load system font: ${match[1]}, installing it could help to have a better PDF rendering.` + ); + } else { + warn( + `Cannot load system font: ${loadedName} for style ${style.style} and weight ${style.weight}.` + ); + } this.removeNativeFontFace(fontFace); } return;