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

Remove the tag for missing font subset when trying to find a substitution #17930

Merged
merged 1 commit into from
Apr 12, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4261,7 +4261,8 @@ class PartialEvaluator {
this.idFactory,
this.options.standardFontDataUrl,
baseFontName,
standardFontName
standardFontName,
type
);
}

Expand Down Expand Up @@ -4381,7 +4382,8 @@ class PartialEvaluator {
this.idFactory,
this.options.standardFontDataUrl,
fontName.name,
standardFontName
standardFontName,
type
);
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/core/font_substitutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,19 +456,29 @@ function generateFont(
* @param {String} baseFontName The font name to be substituted.
* @param {String|undefined} standardFontName The standard font name to use
* if the base font is not available.
* @param {String} type The font type.
* @returns an Object with the CSS, the loaded name, the src and the style.
*/
function getFontSubstitution(
systemFontCache,
idFactory,
localFontPath,
baseFontName,
standardFontName
standardFontName,
type
) {
if (baseFontName.startsWith("InvalidPDFjsFont_")) {
return null;
}

if (
(type === "TrueType" || type === "Type1") &&
/^[A-Z]{6}\+/.test(baseFontName)
calixteman marked this conversation as resolved.
Show resolved Hide resolved
) {
// When the font is a subset, we need to remove the prefix (see 9.6.4).
baseFontName = baseFontName.slice(7);
calixteman marked this conversation as resolved.
Show resolved Hide resolved
}

// It's possible to have a font name with spaces, commas or dashes, hence we
// just replace them by a dash.
baseFontName = normalizeFontName(baseFontName);
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,4 @@
!issue17871_bottom_right.pdf
!issue17871_top_right.pdf
!bug1889122.pdf
!issue17929.pdf
Binary file added test/pdfs/issue17929.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9833,5 +9833,12 @@
"firstPage": 1,
"lastPage": 1,
"type": "eq"
},
{
"id": "issue17929",
"file": "pdfs/issue17929.pdf",
"md5": "2f5686f77f73fb99037f5c2c7e48ce53",
"rounds": 1,
"type": "eq"
}
]
60 changes: 48 additions & 12 deletions test/unit/font_substitutions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,32 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
undefined
undefined,
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
guessFallback: true,
baseFontName: "Foo",
src: "local(Foo)",
style: {
style: "normal",
weight: "normal",
},
})
);
expect(fontSubstitution.css).toMatch(/^"Foo",g_d(\d+)_sf(\d+)$/);
});

it("should substitute an unknown font subset", () => {
const fontName = "ABCDEF+Foo";
const fontSubstitution = getFontSubstitution(
new Map(),
idFactory,
localFontPath,
fontName,
undefined,
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand All @@ -50,7 +75,8 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
undefined
undefined,
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand All @@ -73,7 +99,8 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
undefined
undefined,
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand All @@ -96,7 +123,8 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
undefined
undefined,
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand All @@ -119,7 +147,8 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
"Helvetica"
"Helvetica",
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand Down Expand Up @@ -150,7 +179,8 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
"Helvetica-Oblique"
"Helvetica-Oblique",
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand Down Expand Up @@ -183,7 +213,8 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
"Helvetica-Bold"
"Helvetica-Bold",
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand Down Expand Up @@ -215,7 +246,8 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
"Helvetica-BoldOblique"
"Helvetica-BoldOblique",
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand Down Expand Up @@ -250,7 +282,8 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
undefined
undefined,
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand Down Expand Up @@ -283,7 +316,8 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
undefined
undefined,
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand Down Expand Up @@ -318,7 +352,8 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
undefined
undefined,
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand Down Expand Up @@ -353,7 +388,8 @@ describe("getFontSubstitution", function () {
idFactory,
localFontPath,
fontName,
undefined
undefined,
"TrueType"
);
expect(fontSubstitution).toEqual(
jasmine.objectContaining({
Expand Down