[api-minor] Use a local font or fallback on an embedded one (if it exists) for non-embedded fonts (bug 1766039)

- Replace FoxitSans with LiberationSans: LiberationSans is already there (for XFA) and we can use
it as a good replacement of FoxitSans.
- For now we just try to substitue standard fonts, the strategy is the following:
  * we try to find a font locally from a hardcoded list;
  * if it fails then we use Liberation as fallback (only for Helvetica for the moment);
  * else we just fallback on the system serif/sansserif/monospace font.
This commit is contained in:
Calixte Denizet 2023-04-27 18:01:07 +02:00
parent a24e11a91c
commit 53134c0c0b
12 changed files with 584 additions and 28 deletions

View file

@ -68,6 +68,7 @@ import { bidi } from "./bidi.js";
import { ColorSpace } from "./colorspace.js";
import { DecodeStream } from "./decode_stream.js";
import { FontFlags } from "./fonts_utils.js";
import { getFontSubstitution } from "./font_substitutions.js";
import { getGlyphsUnicode } from "./glyphlist.js";
import { getLookupTableFactory } from "./core_utils.js";
import { getMetrics } from "./metrics.js";
@ -4174,6 +4175,7 @@ class PartialEvaluator {
type,
name: baseFontName,
loadedName: baseDict.loadedName,
systemFontInfo: null,
widths: metrics.widths,
defaultWidth: metrics.defaultWidth,
isSimulatedFlags: true,
@ -4193,6 +4195,14 @@ class PartialEvaluator {
if (standardFontName) {
file = await this.fetchStandardFontData(standardFontName);
properties.isInternalFont = !!file;
if (!properties.isInternalFont && this.options.useSystemFonts) {
properties.systemFontInfo = getFontSubstitution(
this.idFactory,
this.options.standardFontDataUrl,
baseFontName,
standardFontName
);
}
}
return this.extractDataStructures(dict, dict, properties).then(
newProperties => {
@ -4264,6 +4274,7 @@ class PartialEvaluator {
}
let isInternalFont = false;
let glyphScaleFactors = null;
let systemFontInfo = null;
if (fontFile) {
if (fontFile.dict) {
const subtypeEntry = fontFile.dict.get("Subtype");
@ -4296,6 +4307,14 @@ class PartialEvaluator {
if (standardFontName) {
fontFile = await this.fetchStandardFontData(standardFontName);
isInternalFont = !!fontFile;
if (!isInternalFont && this.options.useSystemFonts) {
systemFontInfo = getFontSubstitution(
this.idFactory,
this.options.standardFontDataUrl,
fontName.name,
standardFontName
);
}
}
}
@ -4325,6 +4344,7 @@ class PartialEvaluator {
isType3Font,
cssFontInfo,
scaleFactors: glyphScaleFactors,
systemFontInfo,
};
if (composite) {