Skip to content

Commit

Permalink
Fix two cmap related issues.
Browse files Browse the repository at this point in the history
In issue mozilla#8707, there's a char code mapped to a non-
existing glyph which shouldn't be drawn. However, we
saw it was missing and tried to then use the post table and
end up mapping it incorrectly.

This illuminated a problem with issue mozilla#5704 and bug
893730 where glyphs disappeared after above fix.  This was
from the cmap returning the wrong glyph id. Which in turn was
caused because the font had multiple of the same type of cmap
table and we were choosing the last one. Now, we instead
default to the first one. I'm unsure if we should instead be
merging the multiple cmaps, but using only the first one works.
  • Loading branch information
brendandahl committed Aug 4, 2017
1 parent 5b5781b commit 0bef50d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,13 @@ var Font = (function FontClosure() {
var offset = font.getInt32() >>> 0;
var useTable = false;

// Sometimes there are multiple of the same type of table. Default
// to choosing the first table and skip the rest.
if (potentialTable && potentialTable.platformId === platformId &&
potentialTable.encodingId === encodingId) {
continue;
}

if (platformId === 0 && encodingId === 0) {
useTable = true;
// Continue the loop since there still may be a higher priority
Expand Down Expand Up @@ -2393,11 +2400,9 @@ var Font = (function FontClosure() {
if (cmapMappings[i].charCode !== unicodeOrCharCode) {
continue;
}
if (hasGlyph(cmapMappings[i].glyphId)) {
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
found = true;
break;
}
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
found = true;
break;
}
if (!found && properties.glyphNames) {
// Try to map using the post table.
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
!issue8480.pdf
!issue8570.pdf
!issue8697.pdf
!issue8707.pdf
!bad-PageLabels.pdf
!filled-background.pdf
!ArabicCIDTrueType.pdf
Expand Down
Binary file added test/pdfs/issue8707.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 @@ -682,6 +682,13 @@
"link": false,
"type": "eq"
},
{ "id": "issue8707",
"file": "pdfs/issue8707.pdf",
"md5": "d3dc670adde9ec9fb82c974027033029",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue5509",
"file": "pdfs/issue5509.pdf",
"md5": "1975ef8db7355b1d691bc79d0749574b",
Expand Down

0 comments on commit 0bef50d

Please sign in to comment.