Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for the font substitution #16421

Merged
merged 1 commit into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions test/unit/clitests.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"encodings_spec.js",
"evaluator_spec.js",
"event_utils_spec.js",
"font_substitutions_spec.js",
"function_spec.js",
"message_handler_spec.js",
"metadata_spec.js",
Expand Down
351 changes: 351 additions & 0 deletions test/unit/font_substitutions_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,351 @@
/* Copyright 2022 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { createIdFactory } from "./test_utils.js";
import { getFontSubstitution } from "../../src/core/font_substitutions.js";

describe("getFontSubstitution", function () {
const idFactory = createIdFactory(0);
const localFontPath = "/tmp/";

it("should substitute an unknown font", () => {
const fontName = "Foo";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
undefined
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: true,
src: "local(Foo)",
style: {
style: "normal",
weight: "normal",
},
})
);
});

it("should substitute an unknown bold font", () => {
const fontName = "Foo-Bold";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
undefined
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: true,
src: "local(Foo-Bold)",
style: {
style: "normal",
weight: "bold",
},
})
);
});

it("should substitute an unknown italic font", () => {
const fontName = "Foo-Italic";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
undefined
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: true,
src: "local(Foo-Italic)",
style: {
style: "italic",
weight: "normal",
},
})
);
});

it("should substitute an unknown bold italic font", () => {
const fontName = "Foo-BoldItalic";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
undefined
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: true,
src: "local(Foo-BoldItalic)",
style: {
style: "italic",
weight: "bold",
},
})
);
});

it("should substitute an unknown font but with a standard font", () => {
const fontName = "Foo";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
"Helvetica"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
src:
"local(Foo),local(Helvetica),local(Helvetica Neue)," +
"local(Arial),local(Arial Nova),local(Liberation Sans)," +
"local(Arimo),local(Nimbus Sans),local(Nimbus Sans L)," +
"local(A030),local(TeX Gyre Heros),local(FreeSans)," +
"local(DejaVu Sans),local(Albany),local(Bitstream Vera Sans)," +
"local(Arial Unicode MS),local(Microsoft Sans Serif)," +
"local(Apple Symbols),local(Cantarell)," +
"url(/tmp/LiberationSans-Regular.ttf)",
style: {
style: "normal",
weight: "normal",
},
})
);
});

it("should substitute an unknown font but with a standard italic font", () => {
const fontName = "Foo-Italic";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
"Helvetica-Oblique"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
src:
"local(Foo-Italic),local(Helvetica Italic)," +
"local(Helvetica Neue Italic),local(Arial Italic)," +
"local(Arial Nova Italic),local(Liberation Sans Italic)," +
"local(Arimo Italic),local(Nimbus Sans Italic)," +
"local(Nimbus Sans L Italic),local(A030 Italic)," +
"local(TeX Gyre Heros Italic),local(FreeSans Italic)," +
"local(DejaVu Sans Italic),local(Albany Italic)," +
"local(Bitstream Vera Sans Italic),local(Arial Unicode MS Italic)," +
"local(Microsoft Sans Serif Italic),local(Apple Symbols Italic)," +
"local(Cantarell Italic),url(/tmp/LiberationSans-Italic.ttf)",
style: {
style: "italic",
weight: "normal",
},
})
);
});

it("should substitute an unknown font but with a standard bold font", () => {
const fontName = "Foo-Bold";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
"Helvetica-Bold"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
src:
"local(Foo-Bold),local(Helvetica Bold),local(Helvetica Neue Bold)," +
"local(Arial Bold),local(Arial Nova Bold)," +
"local(Liberation Sans Bold),local(Arimo Bold)," +
"local(Nimbus Sans Bold),local(Nimbus Sans L Bold)," +
"local(A030 Bold),local(TeX Gyre Heros Bold),local(FreeSans Bold)," +
"local(DejaVu Sans Bold),local(Albany Bold)," +
"local(Bitstream Vera Sans Bold),local(Arial Unicode MS Bold)," +
"local(Microsoft Sans Serif Bold),local(Apple Symbols Bold)," +
"local(Cantarell Bold),url(/tmp/LiberationSans-Bold.ttf)",
style: {
style: "normal",
weight: "bold",
},
})
);
});

it("should substitute an unknown font but with a standard bold italic font", () => {
const fontName = "Foo-BoldItalic";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
"Helvetica-BoldOblique"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
src:
"local(Foo-BoldItalic),local(Helvetica Bold Italic)," +
"local(Helvetica Neue Bold Italic),local(Arial Bold Italic)," +
"local(Arial Nova Bold Italic),local(Liberation Sans Bold Italic)," +
"local(Arimo Bold Italic),local(Nimbus Sans Bold Italic)," +
"local(Nimbus Sans L Bold Italic),local(A030 Bold Italic)," +
"local(TeX Gyre Heros Bold Italic),local(FreeSans Bold Italic)," +
"local(DejaVu Sans Bold Italic),local(Albany Bold Italic)," +
"local(Bitstream Vera Sans Bold Italic)," +
"local(Arial Unicode MS Bold Italic)," +
"local(Microsoft Sans Serif Bold Italic)," +
"local(Apple Symbols Bold Italic),local(Cantarell Bold Italic)," +
"url(/tmp/LiberationSans-BoldItalic.ttf)",
style: {
style: "italic",
weight: "bold",
},
})
);
});

it("should substitute Calibri", () => {
const fontName = "Calibri";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
undefined
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
src:
"local(Calibri),local(Carlito),local(Helvetica)," +
"local(Helvetica Neue),local(Arial),local(Arial Nova)," +
"local(Liberation Sans),local(Arimo),local(Nimbus Sans)," +
"local(Nimbus Sans L),local(A030),local(TeX Gyre Heros)," +
"local(FreeSans),local(DejaVu Sans),local(Albany)," +
"local(Bitstream Vera Sans),local(Arial Unicode MS)," +
"local(Microsoft Sans Serif),local(Apple Symbols)," +
"local(Cantarell),url(/tmp/LiberationSans-Regular.ttf)",
style: {
style: "normal",
weight: "normal",
},
})
);
});

it("should substitute Calibri-Bold", () => {
const fontName = "Calibri-Bold";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
undefined
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
src:
"local(Calibri Bold),local(Carlito Bold),local(Helvetica Bold)," +
"local(Helvetica Neue Bold),local(Arial Bold)," +
"local(Arial Nova Bold),local(Liberation Sans Bold)," +
"local(Arimo Bold),local(Nimbus Sans Bold)," +
"local(Nimbus Sans L Bold),local(A030 Bold)," +
"local(TeX Gyre Heros Bold),local(FreeSans Bold)," +
"local(DejaVu Sans Bold),local(Albany Bold)," +
"local(Bitstream Vera Sans Bold),local(Arial Unicode MS Bold)," +
"local(Microsoft Sans Serif Bold),local(Apple Symbols Bold)," +
"local(Cantarell Bold),url(/tmp/LiberationSans-Bold.ttf)",
style: {
style: "normal",
weight: "bold",
},
})
);
});

it("should substitute Arial Black", () => {
const fontName = "Arial Black";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
undefined
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
src:
"local(Arial Black),local(Helvetica Bold)," +
"local(Helvetica Neue Bold),local(Arial Bold)," +
"local(Arial Nova Bold),local(Liberation Sans Bold)," +
"local(Arimo Bold),local(Nimbus Sans Bold)," +
"local(Nimbus Sans L Bold),local(A030 Bold)," +
"local(TeX Gyre Heros Bold),local(FreeSans Bold)," +
"local(DejaVu Sans Bold),local(Albany Bold)," +
"local(Bitstream Vera Sans Bold),local(Arial Unicode MS Bold)," +
"local(Microsoft Sans Serif Bold),local(Apple Symbols Bold)," +
"local(Cantarell Bold),url(/tmp/LiberationSans-Bold.ttf)",
style: {
style: "normal",
weight: "900",
},
})
);
});

it("should substitute Arial Black Bold", () => {
const fontName = "Arial-Black-Bold";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
undefined
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: false,
src:
"local(Arial Black),local(Helvetica Bold)," +
"local(Helvetica Neue Bold),local(Arial Bold)," +
"local(Arial Nova Bold),local(Liberation Sans Bold)," +
"local(Arimo Bold),local(Nimbus Sans Bold)," +
"local(Nimbus Sans L Bold),local(A030 Bold)," +
"local(TeX Gyre Heros Bold),local(FreeSans Bold)," +
"local(DejaVu Sans Bold),local(Albany Bold)," +
"local(Bitstream Vera Sans Bold),local(Arial Unicode MS Bold)," +
"local(Microsoft Sans Serif Bold),local(Apple Symbols Bold)," +
"local(Cantarell Bold),url(/tmp/LiberationSans-Bold.ttf)",
style: {
style: "normal",
weight: "900",
},
})
);
});
});
1 change: 1 addition & 0 deletions test/unit/jasmine-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async function initializePDFJS(callback) {
"pdfjs-test/unit/event_utils_spec.js",
"pdfjs-test/unit/function_spec.js",
"pdfjs-test/unit/fetch_stream_spec.js",
"pdfjs-test/unit/font_substitutions_spec.js",
"pdfjs-test/unit/message_handler_spec.js",
"pdfjs-test/unit/metadata_spec.js",
"pdfjs-test/unit/murmurhash3_spec.js",
Expand Down