diff --git a/src/core/evaluator.js b/src/core/evaluator.js index e1badcec3670b..4f33989d0757e 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -4664,9 +4664,22 @@ class PartialEvaluator { throw new FormatError("invalid font name"); } - let fontFile, subtype, length1, length2, length3; + let fontFile, fontFileN, subtype, length1, length2, length3; try { - fontFile = descriptor.get("FontFile", "FontFile2", "FontFile3"); + fontFile = descriptor.get("FontFile"); + if (fontFile) { + fontFileN = 1; + } else { + fontFile = descriptor.get("FontFile2"); + if (fontFile) { + fontFileN = 2; + } else { + fontFile = descriptor.get("FontFile3"); + if (fontFile) { + fontFileN = 3; + } + } + } if (fontFile) { if (!(fontFile instanceof BaseStream)) { @@ -4776,6 +4789,7 @@ class PartialEvaluator { name: fontName.name, subtype, file: fontFile, + fontFileN, length1, length2, length3, diff --git a/src/core/fonts.js b/src/core/fonts.js index 71c5f3eac60e3..8cf66e1311693 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -2682,10 +2682,23 @@ class Font { } const isTrueType = !tables["CFF "]; + let parsedCff = null; if (!isTrueType) { + try { + parsedCff = new CFFParser( + new Stream(tables["CFF "].data), + properties, + SEAC_ANALYSIS_ENABLED + ).parse(); + } catch { + warn("Failed to parse font " + properties.loadedName); + } + // OpenType font (skip composite fonts with non-default glyph mapping). if ( - (header.version === "OTTO" && !properties.composite) || + (header.version === "OTTO" && + (!properties.composite || + (properties.fontFileN === 3 && parsedCff?.isCIDFont))) || !tables.head || !tables.hhea || !tables.maxp || @@ -2725,19 +2738,11 @@ class Font { } let numGlyphsFromCFF; - if (!isTrueType) { + if (parsedCff) { try { - // Trying to repair CFF file - const parser = new CFFParser( - new Stream(tables["CFF "].data), - properties, - SEAC_ANALYSIS_ENABLED - ); - const cff = parser.parse(); - cff.duplicateFirstGlyph(); - const compiler = new CFFCompiler(cff); - tables["CFF "].data = compiler.compile(); - numGlyphsFromCFF = cff.charStringCount; + parsedCff.duplicateFirstGlyph(); + tables["CFF "].data = new CFFCompiler(parsedCff).compile(); + numGlyphsFromCFF = parsedCff.charStringCount; } catch { warn("Failed to compile font " + properties.loadedName); } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index a0c521f326746..bc6027dc6a5b4 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -921,3 +921,4 @@ !operator_list_cycle.pdf !knockout_groups_test.pdf !issue18032.pdf +!Embedded_font.pdf diff --git a/test/pdfs/Embedded_font.pdf b/test/pdfs/Embedded_font.pdf new file mode 100644 index 0000000000000..823909f92a813 Binary files /dev/null and b/test/pdfs/Embedded_font.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index adc5211c63109..e3d03daa37e93 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -14260,5 +14260,12 @@ "rounds": 1, "type": "eq", "about": "Non-isolated knockout group with a nested non-isolated subgroup over existing text." + }, + { + "id": "Embedded_font.pdf", + "file": "pdfs/Embedded_font.pdf", + "md5": "b68dd5a3e6833d1af94e295fe1d60285", + "rounds": 1, + "type": "eq" } ]