diff --git a/src/core/evaluator.js b/src/core/evaluator.js index c5baf23ee9fc2..5132cc830d0cf 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -4261,7 +4261,8 @@ class PartialEvaluator { this.idFactory, this.options.standardFontDataUrl, baseFontName, - standardFontName + standardFontName, + type ); } @@ -4381,7 +4382,8 @@ class PartialEvaluator { this.idFactory, this.options.standardFontDataUrl, fontName.name, - standardFontName + standardFontName, + type ); } } diff --git a/src/core/font_substitutions.js b/src/core/font_substitutions.js index ec973b84919ff..426e6b47e3034 100644 --- a/src/core/font_substitutions.js +++ b/src/core/font_substitutions.js @@ -456,6 +456,7 @@ 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( @@ -463,12 +464,21 @@ function getFontSubstitution( idFactory, localFontPath, baseFontName, - standardFontName + standardFontName, + type ) { if (baseFontName.startsWith("InvalidPDFjsFont_")) { return null; } + if ( + (type === "TrueType" || type === "Type1") && + /^[A-Z]{6}\+/.test(baseFontName) + ) { + // When the font is a subset, we need to remove the prefix (see 9.6.4). + baseFontName = baseFontName.slice(7); + } + // It's possible to have a font name with spaces, commas or dashes, hence we // just replace them by a dash. baseFontName = normalizeFontName(baseFontName); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index d8515d1c73565..057c3475869f1 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -641,3 +641,4 @@ !issue17871_bottom_right.pdf !issue17871_top_right.pdf !bug1889122.pdf +!issue17929.pdf diff --git a/test/pdfs/issue17929.pdf b/test/pdfs/issue17929.pdf new file mode 100755 index 0000000000000..e062143d095a2 Binary files /dev/null and b/test/pdfs/issue17929.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 85fb66cbe90f6..aa53c3e17df95 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -9833,5 +9833,12 @@ "firstPage": 1, "lastPage": 1, "type": "eq" + }, + { + "id": "issue17929", + "file": "pdfs/issue17929.pdf", + "md5": "2f5686f77f73fb99037f5c2c7e48ce53", + "rounds": 1, + "type": "eq" } ] diff --git a/test/unit/font_substitutions_spec.js b/test/unit/font_substitutions_spec.js index 8b7edd86d0a9a..bad2b76b40c1a 100644 --- a/test/unit/font_substitutions_spec.js +++ b/test/unit/font_substitutions_spec.js @@ -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({ @@ -50,7 +75,8 @@ describe("getFontSubstitution", function () { idFactory, localFontPath, fontName, - undefined + undefined, + "TrueType" ); expect(fontSubstitution).toEqual( jasmine.objectContaining({ @@ -73,7 +99,8 @@ describe("getFontSubstitution", function () { idFactory, localFontPath, fontName, - undefined + undefined, + "TrueType" ); expect(fontSubstitution).toEqual( jasmine.objectContaining({ @@ -96,7 +123,8 @@ describe("getFontSubstitution", function () { idFactory, localFontPath, fontName, - undefined + undefined, + "TrueType" ); expect(fontSubstitution).toEqual( jasmine.objectContaining({ @@ -119,7 +147,8 @@ describe("getFontSubstitution", function () { idFactory, localFontPath, fontName, - "Helvetica" + "Helvetica", + "TrueType" ); expect(fontSubstitution).toEqual( jasmine.objectContaining({ @@ -150,7 +179,8 @@ describe("getFontSubstitution", function () { idFactory, localFontPath, fontName, - "Helvetica-Oblique" + "Helvetica-Oblique", + "TrueType" ); expect(fontSubstitution).toEqual( jasmine.objectContaining({ @@ -183,7 +213,8 @@ describe("getFontSubstitution", function () { idFactory, localFontPath, fontName, - "Helvetica-Bold" + "Helvetica-Bold", + "TrueType" ); expect(fontSubstitution).toEqual( jasmine.objectContaining({ @@ -215,7 +246,8 @@ describe("getFontSubstitution", function () { idFactory, localFontPath, fontName, - "Helvetica-BoldOblique" + "Helvetica-BoldOblique", + "TrueType" ); expect(fontSubstitution).toEqual( jasmine.objectContaining({ @@ -250,7 +282,8 @@ describe("getFontSubstitution", function () { idFactory, localFontPath, fontName, - undefined + undefined, + "TrueType" ); expect(fontSubstitution).toEqual( jasmine.objectContaining({ @@ -283,7 +316,8 @@ describe("getFontSubstitution", function () { idFactory, localFontPath, fontName, - undefined + undefined, + "TrueType" ); expect(fontSubstitution).toEqual( jasmine.objectContaining({ @@ -318,7 +352,8 @@ describe("getFontSubstitution", function () { idFactory, localFontPath, fontName, - undefined + undefined, + "TrueType" ); expect(fontSubstitution).toEqual( jasmine.objectContaining({ @@ -353,7 +388,8 @@ describe("getFontSubstitution", function () { idFactory, localFontPath, fontName, - undefined + undefined, + "TrueType" ); expect(fontSubstitution).toEqual( jasmine.objectContaining({