Skip to content

Commit

Permalink
Merge pull request #14882 from Snuffleupagus/issue-14881
Browse files Browse the repository at this point in the history
Add support for TrueType format 12 `cmap`s (issue 14881)
  • Loading branch information
timvandermeij authored May 7, 2022
2 parents 0a34b3b + 6e7e9d8 commit f8838eb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
!issue2391-2.pdf
!issue14046.pdf
!issue7891_bc1.pdf
!issue14881.pdf
!issue3214.pdf
!issue4665.pdf
!issue4684.pdf
Expand Down
Binary file added test/pdfs/issue14881.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f8838eb

Please sign in to comment.