Only mask char codes of (3, 0) cmap tables in the range of 0xF000 to 0xF0FF.

This commit is contained in:
Brendan Dahl 2017-06-29 17:14:58 -07:00
parent 87a0031d77
commit efbbd8533f
4 changed files with 24 additions and 14 deletions

View File

@ -2406,21 +2406,23 @@ var Font = (function FontClosure() {
cmapMappings[i].glyphId; cmapMappings[i].glyphId;
} }
} else { } else {
// For (3, 0) cmap tables: // When there is only a (1, 0) cmap table, the char code is a single
// The charcode key being stored in charCodeToGlyphId is the lower // byte and it is used directly as the char code.
// 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 // When a (3, 0) cmap table is present, it is used instead but the
// high byte of the range [of charcodes in the cmap table], to form // spec has special rules for char codes in the range of 0xF000 to
// a two-byte character, which shall be used to select the // 0xF0FF and it says the (3, 0) table should map the values from
// associated glyph description from the subtable'. // 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
// For (1, 0) cmap tables: // special range since some PDFs have char codes outside of this range
// 'single bytes from the string shall be used to look up the // (e.g. 0x2013) which when masked would overwrite other values in the
// associated glyph descriptions from the subtable'. This means // cmap.
// charcodes in the cmap will be single bytes, so no-op since
// glyph.charCode & 0xFF === glyph.charCode
for (i = 0; i < cmapMappingsLength; ++i) { 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; charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
} }
} }

View File

@ -269,6 +269,7 @@
!issue6113.pdf !issue6113.pdf
!openoffice.pdf !openoffice.pdf
!issue7014.pdf !issue7014.pdf
!issue8187.pdf
!annotation-link-text-popup.pdf !annotation-link-text-popup.pdf
!annotation-text-without-popup.pdf !annotation-text-without-popup.pdf
!annotation-underline.pdf !annotation-underline.pdf

BIN
test/pdfs/issue8187.pdf Normal file

Binary file not shown.

View File

@ -1863,6 +1863,13 @@
"link": false, "link": false,
"type": "eq" "type": "eq"
}, },
{ "id": "issue8187",
"file": "pdfs/issue8187.pdf",
"md5": "1724dcada47b90c9217ee0139d8352a8",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue5686", { "id": "issue5686",
"file": "pdfs/issue5686.pdf", "file": "pdfs/issue5686.pdf",
"md5": "78d16b9df07a355ad00d70504a9194f8", "md5": "78d16b9df07a355ad00d70504a9194f8",