From 52ea2333b37f8bbd3cd1b0b9779e65212b1c6003 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 11 Apr 2024 17:55:11 +0200 Subject: [PATCH] Remove the tag for missing font subset when trying to find a substitution Fixes #17929. --- src/core/evaluator.js | 6 ++- src/core/font_substitutions.js | 12 +++++- test/pdfs/.gitignore | 1 + test/pdfs/issue17929.pdf | Bin 0 -> 7352 bytes test/test_manifest.json | 7 ++++ test/unit/font_substitutions_spec.js | 60 +++++++++++++++++++++------ 6 files changed, 71 insertions(+), 15 deletions(-) create mode 100755 test/pdfs/issue17929.pdf diff --git a/src/core/evaluator.js b/src/core/evaluator.js index c5baf23ee..5132cc830 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 ec973b849..426e6b47e 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 d8515d1c7..057c34758 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 0000000000000000000000000000000000000000..e062143d095a228a58abfe040cf539e86fb33cec GIT binary patch literal 7352 zcmeHMeQaCTb-(xVLoy@FlJ#LHbeu~+%a+B*Pf3(yD~j|;N>=3$eK{s$$KezCBr%gn zhNL{XAC9^-Tc)hduwg*ac15tiJK$38PURJNB|}{|%Es-gD16_uO-S=iKui-|Lx8Oa>ysK~K+L|NEca_e4Zk6qjE0jE;)X z;;oV?LYJ3bU8t^$&;_%wQe73%=&%S~68$1HnJ-tWA~Gn(#ypj3*)-NYQLOG40|R0} zM21EzBk|%!0a_w7lh0MeH4%f#ym+}`eb!hpD`bH-jKfGZUo0eyswsLCXQSchKzJY$ ziS!SSM5F$2^mI6Urmj{ji(YtOE*Ce&rTofjb?ugjL}S6Q5rN8VxtQC?n$XD_`EpT2 zf{~%%fVkefTCJ8UXG0;2y;3$xtNCmtSS+txKXazxhV2u@GT(4BZd8r6;tFY)grly@l{W9(KGjHz{$^s2g%Lq)Iyc&g|LEk3$h6U zJ8R$@NDvs4MFdPDdy5fRn73tQo{SNzVN^FNrnMq8G40v%3)x~WUqEL3d2C^d2*J8nm9~#p^SSCO9W5K>|IK%-e*^_$7de4p zIoLpDqLQVuiG*V#IDlQeSTj~CR>b6@ZdYL-G8h{Yfsv6x zF%%gZv=^crNoCSl&*K31P89_qEgpdyC)(1=ubEMtavKBUTr$>i7XEu#n#K{%XD13P zYbFeY7OLj@c|pDt^`b@DaFgMES=tB3{_a?>{r>)80<7K=Lh#9GK2Qp0C~tVA%r=D`t3v6%pGd zsxE9 zl`&prOnE7LvnsrQqnnI5{ti5SxwNvr6gv17#$26@wYIFR-CCZz(b)_O-@)hJs%hk6 z@5^@>>kyd7R>64YXx9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~FV4eQ-O-C0UHXNRn6LB()<@Q6{z+yyFv t54w{B`F1|bxJzT)jo#|L!#@4Kr&2Y_)lIzW^9+SYBA%X} { + 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({