Skip to content

Commit

Permalink
Only mask char codes of (3, 0) cmap tables in the range of 0xF00 to 0…
Browse files Browse the repository at this point in the history
…xF0FF.
  • Loading branch information
brendandahl committed Jun 30, 2017
1 parent 87a0031 commit cbd918e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2406,21 +2406,23 @@ var Font = (function FontClosure() {
cmapMappings[i].glyphId;
}
} else {
// For (3, 0) cmap tables:
// The charcode key being stored in charCodeToGlyphId is the lower
// byte of the two-byte charcodes of the cmap table since according to
// the spec: 'each byte from the string shall be prepended with the
// high byte of the range [of charcodes in the cmap table], to form
// a two-byte character, which shall be used to select the
// associated glyph description from the subtable'.
//
// For (1, 0) cmap tables:
// 'single bytes from the string shall be used to look up the
// associated glyph descriptions from the subtable'. This means
// charcodes in the cmap will be single bytes, so no-op since
// glyph.charCode & 0xFF === glyph.charCode
// When there is only a (1, 0) cmap table, the char code is a single
// byte and it is used directly as the char code.

// When a (3, 0) cmap table is present, it is used instead but the
// spec has special rules for char codes in the range of 0xF00 to
// 0xF0FF and it says the (3, 0) table should map the values from
// the (1, 0) table by prepending 0xF0 to the char codes. To reverse
// this, the upper bits of the char code are cleared, but only for the
// special range since some PDFs have char codes outside of this range
// (e.g. 0x2013) which when masked would overwrite other values in the
// cmap.
for (i = 0; i < cmapMappingsLength; ++i) {
charCode = cmapMappings[i].charCode & 0xFF;
charCode = cmapMappings[i].charCode;
if (cmapPlatformId === 3 &&
(charCode >= 0xF000 && charCode <= 0xF0FF)) {
charCode &= 0xFF;
}
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
}
}
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
!issue6113.pdf
!openoffice.pdf
!issue7014.pdf
!issue8187.pdf
!annotation-link-text-popup.pdf
!annotation-text-without-popup.pdf
!annotation-underline.pdf
Expand Down
Binary file added test/pdfs/issue8187.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 @@ -1863,6 +1863,13 @@
"link": false,
"type": "eq"
},
{ "id": "issue8187",
"file": "pdfs/issue8187.pdf",
"md5": "1724dcada47b90c9217ee0139d8352a8",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue5686",
"file": "pdfs/issue5686.pdf",
"md5": "78d16b9df07a355ad00d70504a9194f8",
Expand Down

0 comments on commit cbd918e

Please sign in to comment.