Skip to content

Commit

Permalink
Merge pull request #17930 from calixteman/issue17929
Browse files Browse the repository at this point in the history
Remove the tag for missing font subset when trying to find a substitution
  • Loading branch information
timvandermeij authored Apr 12, 2024
2 parents f0ad4f0 + 52ea233 commit 2d885e2
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 15 deletions.
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)
) {
// 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);
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

0 comments on commit 2d885e2

Please sign in to comment.