For missing font, use a local font if it exists even if there's no standard substitution
If the font foo is missing we just try lo load local(foo) and maybe we'll be lucky.
This commit is contained in:
parent
e738e15aa3
commit
d4b70ec306
@ -3921,6 +3921,9 @@ class PartialEvaluator {
|
|||||||
}
|
}
|
||||||
if (isMonospace) {
|
if (isMonospace) {
|
||||||
properties.flags |= FontFlags.FixedPitch;
|
properties.flags |= FontFlags.FixedPitch;
|
||||||
|
} else {
|
||||||
|
// Clear the flag.
|
||||||
|
properties.flags &= ~FontFlags.FixedPitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
properties.defaultWidth = defaultWidth;
|
properties.defaultWidth = defaultWidth;
|
||||||
@ -4197,15 +4200,15 @@ class PartialEvaluator {
|
|||||||
if (standardFontName) {
|
if (standardFontName) {
|
||||||
file = await this.fetchStandardFontData(standardFontName);
|
file = await this.fetchStandardFontData(standardFontName);
|
||||||
properties.isInternalFont = !!file;
|
properties.isInternalFont = !!file;
|
||||||
if (!properties.isInternalFont && this.options.useSystemFonts) {
|
}
|
||||||
properties.systemFontInfo = getFontSubstitution(
|
if (!properties.isInternalFont && this.options.useSystemFonts) {
|
||||||
this.systemFontCache,
|
properties.systemFontInfo = getFontSubstitution(
|
||||||
this.idFactory,
|
this.systemFontCache,
|
||||||
this.options.standardFontDataUrl,
|
this.idFactory,
|
||||||
baseFontName,
|
this.options.standardFontDataUrl,
|
||||||
standardFontName
|
baseFontName,
|
||||||
);
|
standardFontName
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
return this.extractDataStructures(dict, dict, properties).then(
|
return this.extractDataStructures(dict, dict, properties).then(
|
||||||
newProperties => {
|
newProperties => {
|
||||||
@ -4310,15 +4313,15 @@ class PartialEvaluator {
|
|||||||
if (standardFontName) {
|
if (standardFontName) {
|
||||||
fontFile = await this.fetchStandardFontData(standardFontName);
|
fontFile = await this.fetchStandardFontData(standardFontName);
|
||||||
isInternalFont = !!fontFile;
|
isInternalFont = !!fontFile;
|
||||||
if (!isInternalFont && this.options.useSystemFonts) {
|
}
|
||||||
systemFontInfo = getFontSubstitution(
|
if (!isInternalFont && this.options.useSystemFonts) {
|
||||||
this.systemFontCache,
|
systemFontInfo = getFontSubstitution(
|
||||||
this.idFactory,
|
this.systemFontCache,
|
||||||
this.options.standardFontDataUrl,
|
this.idFactory,
|
||||||
fontName.name,
|
this.options.standardFontDataUrl,
|
||||||
standardFontName
|
fontName.name,
|
||||||
);
|
standardFontName
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,6 @@ const substitutionMap = new Map([
|
|||||||
[
|
[
|
||||||
"ArialBlack-Italic",
|
"ArialBlack-Italic",
|
||||||
{
|
{
|
||||||
prepend: ["Arial Black Italic"],
|
|
||||||
local: {
|
local: {
|
||||||
alias: "ArialBlack",
|
alias: "ArialBlack",
|
||||||
append: "Italic",
|
append: "Italic",
|
||||||
@ -337,6 +336,8 @@ const fontAliases = new Map([["Arial-Black", "ArialBlack"]]);
|
|||||||
/**
|
/**
|
||||||
* Create the src path to use to load a font (see FontFace).
|
* Create the src path to use to load a font (see FontFace).
|
||||||
* @param {Array<String>} prepend A list of font names to search first.
|
* @param {Array<String>} prepend A list of font names to search first.
|
||||||
|
* @param {String} appendToPrepended A String to append to the list of fonts in
|
||||||
|
* prepend.
|
||||||
* @param {Array<String>|Object} local A list of font names to search. If an
|
* @param {Array<String>|Object} local A list of font names to search. If an
|
||||||
* Object is passed, then local.alias is the name of an other substition font
|
* Object is passed, then local.alias is the name of an other substition font
|
||||||
* and local.append is a String to append to the list of fonts in the alias.
|
* and local.append is a String to append to the list of fonts in the alias.
|
||||||
@ -344,7 +345,7 @@ const fontAliases = new Map([["Arial-Black", "ArialBlack"]]);
|
|||||||
* list of fonts will be "FooSubst1 Bold", "FooSubst2 Bold", etc.
|
* list of fonts will be "FooSubst1 Bold", "FooSubst2 Bold", etc.
|
||||||
* @returns an String with the local fonts.
|
* @returns an String with the local fonts.
|
||||||
*/
|
*/
|
||||||
function makeLocal(prepend, local) {
|
function makeLocal(prepend, appendToPrepended, local) {
|
||||||
let append = "";
|
let append = "";
|
||||||
if (!Array.isArray(local)) {
|
if (!Array.isArray(local)) {
|
||||||
// We are getting our list of fonts in the alias and we'll append Bold,
|
// We are getting our list of fonts in the alias and we'll append Bold,
|
||||||
@ -352,9 +353,14 @@ function makeLocal(prepend, local) {
|
|||||||
append = ` ${local.append}`;
|
append = ` ${local.append}`;
|
||||||
local = substitutionMap.get(local.alias).local;
|
local = substitutionMap.get(local.alias).local;
|
||||||
}
|
}
|
||||||
|
if (appendToPrepended) {
|
||||||
|
appendToPrepended = ` ${appendToPrepended}`;
|
||||||
|
}
|
||||||
|
|
||||||
let prependedPaths = "";
|
let prependedPaths = "";
|
||||||
if (prepend) {
|
if (prepend) {
|
||||||
prependedPaths = prepend.map(name => `local(${name})`).join(",") + ",";
|
prependedPaths =
|
||||||
|
prepend.map(name => `local(${name}${appendToPrepended})`).join(",") + ",";
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
prependedPaths + local.map(name => `local(${name}${append})`).join(",")
|
prependedPaths + local.map(name => `local(${name}${append})`).join(",")
|
||||||
@ -378,8 +384,8 @@ function makeLocal(prepend, local) {
|
|||||||
* @param {Object} idFactory The ids factory.
|
* @param {Object} idFactory The ids factory.
|
||||||
* @param {String} localFontPath Path to the fonts directory.
|
* @param {String} localFontPath Path to the fonts directory.
|
||||||
* @param {String} baseFontName The font name to be substituted.
|
* @param {String} baseFontName The font name to be substituted.
|
||||||
* @param {String} standardFontName The standard font name to use if the base
|
* @param {String|undefined} standardFontName The standard font name to use
|
||||||
* font is not available.
|
* if the base font is not available.
|
||||||
* @returns an Object with the CSS, the loaded name, the src and the style.
|
* @returns an Object with the CSS, the loaded name, the src and the style.
|
||||||
*/
|
*/
|
||||||
function getFontSubstitution(
|
function getFontSubstitution(
|
||||||
@ -437,7 +443,8 @@ function getFontSubstitution(
|
|||||||
(italic && ITALIC) ||
|
(italic && ITALIC) ||
|
||||||
NORMAL;
|
NORMAL;
|
||||||
substitutionInfo = {
|
substitutionInfo = {
|
||||||
css: `${loadedName},sans-serif`,
|
css: loadedName,
|
||||||
|
guessFallback: true,
|
||||||
loadedName,
|
loadedName,
|
||||||
src: `local(${baseFontName})`,
|
src: `local(${baseFontName})`,
|
||||||
style,
|
style,
|
||||||
@ -457,16 +464,20 @@ function getFontSubstitution(
|
|||||||
|
|
||||||
// Prepend the fonts to test before the fallback font.
|
// Prepend the fonts to test before the fallback font.
|
||||||
let prepend = substitution.prepend;
|
let prepend = substitution.prepend;
|
||||||
|
let appendToPrepended = "";
|
||||||
|
|
||||||
if (fallback) {
|
if (fallback) {
|
||||||
// We've a fallback font: this one is a standard font we want to use in case
|
// We've a fallback font: this one is a standard font we want to use in case
|
||||||
// nothing has been found from the prepend list.
|
// nothing has been found from the prepend list.
|
||||||
prepend ||= substitutionMap.get(substitution.local.alias).prepend;
|
if (substitution.local) {
|
||||||
|
prepend ||= substitutionMap.get(substitution.local.alias).prepend;
|
||||||
|
appendToPrepended = substitution.local.append;
|
||||||
|
}
|
||||||
substitution = substitutionMap.get(fallback);
|
substitution = substitutionMap.get(fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { local, path, ultimate } = substitution;
|
const { local, path, ultimate } = substitution;
|
||||||
let src = makeLocal(prepend, local);
|
let src = makeLocal(prepend, appendToPrepended, local);
|
||||||
if (path && localFontPath !== null) {
|
if (path && localFontPath !== null) {
|
||||||
// PDF.js embeds some fonts we can use.
|
// PDF.js embeds some fonts we can use.
|
||||||
src += `,url(${localFontPath}${path})`;
|
src += `,url(${localFontPath}${path})`;
|
||||||
@ -480,6 +491,7 @@ function getFontSubstitution(
|
|||||||
|
|
||||||
substitutionInfo = {
|
substitutionInfo = {
|
||||||
css: `${loadedName},${ultimate}`,
|
css: `${loadedName},${ultimate}`,
|
||||||
|
guessFallback: false,
|
||||||
loadedName,
|
loadedName,
|
||||||
src,
|
src,
|
||||||
style,
|
style,
|
||||||
|
@ -986,6 +986,7 @@ class Font {
|
|||||||
let { type, subtype } = properties;
|
let { type, subtype } = properties;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.subtype = subtype;
|
this.subtype = subtype;
|
||||||
|
this.systemFontInfo = properties.systemFontInfo;
|
||||||
|
|
||||||
const matches = name.match(/^InvalidPDFjsFont_(.*)_\d+$/);
|
const matches = name.match(/^InvalidPDFjsFont_(.*)_\d+$/);
|
||||||
this.isInvalidPDFjsFont = !!matches;
|
this.isInvalidPDFjsFont = !!matches;
|
||||||
@ -999,7 +1000,10 @@ class Font {
|
|||||||
this.fallbackName = "sans-serif";
|
this.fallbackName = "sans-serif";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.systemFontInfo = properties.systemFontInfo;
|
if (this.systemFontInfo?.guessFallback) {
|
||||||
|
this.systemFontInfo.css += `,${this.fallbackName}`;
|
||||||
|
}
|
||||||
|
|
||||||
this.differences = properties.differences;
|
this.differences = properties.differences;
|
||||||
this.widths = properties.widths;
|
this.widths = properties.widths;
|
||||||
this.defaultWidth = properties.defaultWidth;
|
this.defaultWidth = properties.defaultWidth;
|
||||||
|
@ -58,6 +58,9 @@ const getStdFontMap = getLookupTableFactory(function (t) {
|
|||||||
t["Arial-BoldItalicMT"] = "Helvetica-BoldOblique";
|
t["Arial-BoldItalicMT"] = "Helvetica-BoldOblique";
|
||||||
t["Arial-BoldMT"] = "Helvetica-Bold";
|
t["Arial-BoldMT"] = "Helvetica-Bold";
|
||||||
t["Arial-ItalicMT"] = "Helvetica-Oblique";
|
t["Arial-ItalicMT"] = "Helvetica-Oblique";
|
||||||
|
t["Arial-BoldItalicMT-BoldItalic"] = "Helvetica-BoldOblique";
|
||||||
|
t["Arial-BoldMT-Bold"] = "Helvetica-Bold";
|
||||||
|
t["Arial-ItalicMT-Italic"] = "Helvetica-Oblique";
|
||||||
t.ArialUnicodeMS = "Helvetica";
|
t.ArialUnicodeMS = "Helvetica";
|
||||||
t["ArialUnicodeMS-Bold"] = "Helvetica-Bold";
|
t["ArialUnicodeMS-Bold"] = "Helvetica-Bold";
|
||||||
t["ArialUnicodeMS-BoldItalic"] = "Helvetica-BoldOblique";
|
t["ArialUnicodeMS-BoldItalic"] = "Helvetica-BoldOblique";
|
||||||
|
@ -97,9 +97,17 @@ class FontLoader {
|
|||||||
await fontFace.load();
|
await fontFace.load();
|
||||||
this.#systemFonts.add(loadedName);
|
this.#systemFonts.add(loadedName);
|
||||||
} catch {
|
} catch {
|
||||||
warn(
|
if (info.guessFallback) {
|
||||||
`Cannot load system font: ${loadedName} for style ${style.style} and weight ${style.weight}.`
|
// 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 improve PDF rendering.`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
warn(
|
||||||
|
`Cannot load system font: ${loadedName} for style ${style.style} and weight ${style.weight}.`
|
||||||
|
);
|
||||||
|
}
|
||||||
this.removeNativeFontFace(fontFace);
|
this.removeNativeFontFace(fontFace);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user