Skip to content

Commit

Permalink
Fallback to attempt to recover standard glyph names when amending the…
Browse files Browse the repository at this point in the history
… `charCodeToGlyphId` with entries from the `differences` array in `type1FontGlyphMapping` (issue 7439)

Fixes 7439.
  • Loading branch information
Snuffleupagus committed Jun 25, 2016
1 parent 671f33a commit 7866109
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src/core/fonts.js
Expand Up @@ -185,6 +185,25 @@ function getFontType(type, subtype) {
}
}

// Some bad PDF generators, e.g. Scribus PDF, include glyph names
// in a 'uniXXXX' format -- attempting to recover proper ones.
function recoverGlyphName(name, glyphsUnicodeMap) {
if (glyphsUnicodeMap[name] !== undefined) {
return name;
}
// The glyph name is non-standard, trying to recover.
var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
if (unicode !== -1) {
for (var key in glyphsUnicodeMap) {
if (glyphsUnicodeMap[key] === unicode) {
return key;
}
}
}
warn('Unable to recover a standard glyph name for: ' + name);
return name;
}

var Glyph = (function GlyphClosure() {
function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
isSpace, isInFont) {
Expand Down Expand Up @@ -2266,26 +2285,6 @@ var Font = (function FontClosure() {
return false;
}

// Some bad PDF generators, e.g. Scribus PDF, include glyph names
// in a 'uniXXXX' format -- attempting to recover proper ones.
function recoverGlyphName(name, glyphsUnicodeMap) {
if (glyphsUnicodeMap[name] !== undefined) {
return name;
}
// The glyph name is non-standard, trying to recover.
var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
if (unicode !== -1) {
for (var key in glyphsUnicodeMap) {
if (glyphsUnicodeMap[key] === unicode) {
return key;
}
}
}
warn('Unable to recover a standard glyph name for: ' + name);
return name;
}


if (properties.type === 'CIDFontType2') {
var cidToGidMap = properties.cidToGidMap || [];
var isCidToGidMapEmpty = cidToGidMap.length === 0;
Expand Down Expand Up @@ -2859,11 +2858,21 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
}

// Lastly, merge in the differences.
var differences = properties.differences;
var differences = properties.differences, glyphsUnicodeMap;
if (differences) {
for (charCode in differences) {
var glyphName = differences[charCode];
glyphId = glyphNames.indexOf(glyphName);

if (glyphId === -1) {
if (!glyphsUnicodeMap) {
glyphsUnicodeMap = getGlyphsUnicode();
}
var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
if (standardGlyphName !== glyphName) {
glyphId = glyphNames.indexOf(standardGlyphName);
}
}
if (glyphId >= 0) {
charCodeToGlyphId[charCode] = glyphId;
} else {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Expand Up @@ -26,6 +26,7 @@
!issue7115.pdf
!issue7200.pdf
!issue7229.pdf
!issue7439.pdf
!filled-background.pdf
!ArabicCIDTrueType.pdf
!ThuluthFeatures.pdf
Expand Down
Binary file added test/pdfs/issue7439.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Expand Up @@ -1701,6 +1701,13 @@
"link": false,
"type": "eq"
},
{ "id": "issue7439",
"file": "pdfs/issue7439.pdf",
"md5": "56682657990a894c66db26560d3039d7",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "bug867484",
"file": "pdfs/bug867484.pdf",
"md5": "347af7b0ef7279b1a7f43b03bfda4548",
Expand Down

0 comments on commit 7866109

Please sign in to comment.