Merge pull request #1253 from brendandahl/issue925

Fix bad chars in Type2CFF font names.
This commit is contained in:
notmasteryet 2012-02-20 16:57:36 -08:00
commit f4aff1d848
4 changed files with 43 additions and 0 deletions

View File

@ -3321,7 +3321,9 @@ var Type2CFF = (function Type2CFFClosure() {
parse: function cff_parse() {
var header = this.parseHeader();
var properties = this.properties;
var nameIndex = this.parseIndex(header.endPos);
this.sanitizeName(nameIndex);
var dictIndex = this.parseIndex(nameIndex.endPos);
if (dictIndex.length != 1)
@ -3690,6 +3692,39 @@ var Type2CFF = (function Type2CFFClosure() {
}
return dict;
},
sanitizeName: function cff_sanitizeName(nameIndex) {
// There should really only be one font, but loop to make sure.
for (var i = 0, ii = nameIndex.length; i < ii; ++i) {
var data = nameIndex.get(i).data;
var length = data.length;
if (length > 127)
warn('Font had name longer than 127 chars, will be rejected.');
// Only certain chars are permitted in the font name.
for (var j = 0; j < length; ++j) {
var c = data[j];
if (j === 0 && c === 0)
continue;
if (c < 33 || c > 126) {
data[j] = 95;
continue;
}
switch (c) {
case 91: // [
case 93: // ]
case 40: // (
case 41: // )
case 123: // {
case 125: // }
case 60: // <
case 62: // >
case 47: // /
case 37: // %
data[j] = 95;
break;
}
}
}
},
getStrings: function cff_getStrings(stringIndex) {
function bytesToString(bytesArray) {
var str = '';

View File

@ -24,3 +24,4 @@
!type4psfunc.pdf
!S2.pdf
!zerowidthline.pdf
!issue925.pdf

BIN
test/pdfs/issue925.pdf Executable file

Binary file not shown.

View File

@ -460,6 +460,13 @@
"link": true,
"type": "eq"
},
{ "id": "issue925",
"file": "pdfs/issue925.pdf",
"md5": "f58fe943090aff89dcc8e771bc0db4c2",
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "issue1133",
"file": "pdfs/issue1133.pdf",
"md5": "d1b61580cb100e3df93d33703af1773a",