diff --git a/src/core/fonts.js b/src/core/fonts.js index f8b6ad740..22ebf3686 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -1499,14 +1499,14 @@ class Font { } const format = file.getUint16(); - file.skip(2 + 2); // length + language - let hasShortCmap = false; const mappings = []; let j, glyphId; // TODO(mack): refactor this cmap subtable reading logic out if (format === 0) { + file.skip(2 + 2); // length + language + for (j = 0; j < 256; j++) { const index = file.getByte(); if (!index) { @@ -1519,6 +1519,8 @@ class Font { } hasShortCmap = true; } else if (format === 2) { + file.skip(2 + 2); // length + language + const subHeaderKeys = []; let maxSubHeaderKey = 0; // Read subHeaderKeys. If subHeaderKeys[i] === 0, then i is a @@ -1568,6 +1570,8 @@ class Font { } } } else if (format === 4) { + file.skip(2 + 2); // length + language + // re-creating the table in format 4 since the encoding // might be changed const segCount = file.getUint16() >> 1; @@ -1630,6 +1634,8 @@ class Font { } } } else if (format === 6) { + file.skip(2 + 2); // length + language + // Format 6 is a 2-bytes dense mapping, which means the font data // lives glue together even if they are pretty far in the unicode // table. (This looks weird, so I can have missed something), this @@ -1647,6 +1653,26 @@ class Font { glyphId, }); } + } else if (format === 12) { + file.skip(2 + 4 + 4); // reserved + length + language + + const nGroups = file.getInt32() >>> 0; + for (j = 0; j < nGroups; j++) { + const startCharCode = file.getInt32() >>> 0; + const endCharCode = file.getInt32() >>> 0; + let glyphCode = file.getInt32() >>> 0; + + for ( + let charCode = startCharCode; + charCode <= endCharCode; + charCode++ + ) { + mappings.push({ + charCode, + glyphId: glyphCode++, + }); + } + } } else { warn("cmap table has unsupported format: " + format); return { diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 2dc4fcd79..e11b5f45d 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -18,6 +18,7 @@ !issue2391-2.pdf !issue14046.pdf !issue7891_bc1.pdf +!issue14881.pdf !issue3214.pdf !issue4665.pdf !issue4684.pdf diff --git a/test/pdfs/issue14881.pdf b/test/pdfs/issue14881.pdf new file mode 100644 index 000000000..ac23b2693 Binary files /dev/null and b/test/pdfs/issue14881.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 451a32281..247097f8e 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -4630,6 +4630,12 @@ "password": "\u00E6\u00F8\u00E5", "about": "The password (æøå) is UTF8 encoded." }, + { "id": "issue14881", + "file": "pdfs/issue14881.pdf", + "md5": "1aa3f2c7929eaf4502fcf6488ff31b5f", + "rounds": 1, + "type": "eq" + }, { "id": "High-Pressure-Measurement-WP-001287", "file": "pdfs/High-Pressure-Measurement-WP-001287.pdf", "md5": "aeba7e47bbe50cbf08bb8bdff78fec8c",