Warn when pdf.js can't load an OS font

This commit is contained in:
Calixte Denizet 2023-05-16 14:58:38 +02:00
parent 95ab2b8b17
commit 385f275ad9
3 changed files with 18 additions and 11 deletions

View File

@ -451,6 +451,7 @@ function getFontSubstitution(
css: loadedName,
guessFallback: true,
loadedName,
baseFontName,
src: `local(${baseFontName})`,
style,
};
@ -470,6 +471,7 @@ function getFontSubstitution(
css: `${loadedName},${ultimate}`,
guessFallback: false,
loadedName,
baseFontName,
src: src.join(","),
style,
};

View File

@ -97,17 +97,10 @@ class FontLoader {
await fontFace.load();
this.#systemFonts.add(loadedName);
} catch {
if (info.guessFallback) {
// 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}.`
);
}
warn(
`Cannot load system font: ${info.baseFontName}, installing it could help to improve PDF rendering.`
);
this.removeNativeFontFace(fontFace);
}
return;

View File

@ -32,6 +32,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: true,
baseFontName: "Foo",
src: "local(Foo)",
style: {
style: "normal",
@ -54,6 +55,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: true,
baseFontName: "Foo-Bold",
src: "local(Foo-Bold)",
style: {
style: "normal",
@ -76,6 +78,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: true,
baseFontName: "Foo-Italic",
src: "local(Foo-Italic)",
style: {
style: "italic",
@ -98,6 +101,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: true,
baseFontName: "Foo-BoldItalic",
src: "local(Foo-BoldItalic)",
style: {
style: "italic",
@ -120,6 +124,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
baseFontName: "Foo",
src:
"local(Foo),local(Helvetica),local(Helvetica Neue)," +
"local(Arial),local(Arial Nova),local(Liberation Sans)," +
@ -150,6 +155,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
baseFontName: "Foo-Italic",
src:
"local(Foo-Italic),local(Helvetica Italic)," +
"local(Helvetica Neue Italic),local(Arial Italic)," +
@ -182,6 +188,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
baseFontName: "Foo-Bold",
src:
"local(Foo-Bold),local(Helvetica Bold),local(Helvetica Neue Bold)," +
"local(Arial Bold),local(Arial Nova Bold)," +
@ -213,6 +220,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
baseFontName: "Foo-BoldItalic",
src:
"local(Foo-BoldItalic),local(Helvetica Bold Italic)," +
"local(Helvetica Neue Bold Italic),local(Arial Bold Italic)," +
@ -247,6 +255,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
baseFontName: "Calibri",
src:
"local(Calibri),local(Carlito),local(Helvetica)," +
"local(Helvetica Neue),local(Arial),local(Arial Nova)," +
@ -277,6 +286,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
baseFontName: "Calibri-Bold",
src:
"local(Calibri Bold),local(Carlito Bold),local(Helvetica Bold)," +
"local(Helvetica Neue Bold),local(Arial Bold)," +
@ -309,6 +319,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
baseFontName: "ArialBlack",
src:
"local(Arial Black),local(Helvetica Bold)," +
"local(Helvetica Neue Bold),local(Arial Bold)," +
@ -341,6 +352,7 @@ describe("getFontSubstitution", function () {
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
baseFontName: "ArialBlack-Bold",
src:
"local(Arial Black),local(Helvetica Bold)," +
"local(Helvetica Neue Bold),local(Arial Bold)," +