Do not use stream when it is not necessary
This commit is contained in:
parent
d31bc90c85
commit
35ceea1ff2
53
PDFFont.js
53
PDFFont.js
@ -990,32 +990,30 @@ var Type1Parser = function() {
|
|||||||
"31": "hvcurveto"
|
"31": "hvcurveto"
|
||||||
};
|
};
|
||||||
|
|
||||||
function decodeCharString(aStream) {
|
function decodeCharString(aArray) {
|
||||||
var start = Date.now();
|
|
||||||
var charString = [];
|
var charString = [];
|
||||||
|
|
||||||
var value = "";
|
var value = "";
|
||||||
var count = aStream.length;
|
var count = aArray.length;
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
value = aStream.getByte();
|
value = parseInt(aArray[i]);
|
||||||
|
|
||||||
if (value < 32) {
|
if (value < 32) {
|
||||||
var command = null;
|
var command = null;
|
||||||
if (value == 12) {
|
if (value == 12) {
|
||||||
var escape = aStream.getByte();
|
var escape = aArray[++i];
|
||||||
command = charStringDictionary["12"][escape];
|
command = charStringDictionary["12"][escape];
|
||||||
i++;
|
|
||||||
} else {
|
} else {
|
||||||
command = charStringDictionary[value];
|
command = charStringDictionary[value];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some charstring commands are meaningless in Type2 and will return
|
// Some charstring commands are meaningless in Type2 and will return
|
||||||
// a null, let's just ignored them
|
// a null, let's just ignored them
|
||||||
if (!command && i < count)
|
if (!command && i < count) {
|
||||||
continue;
|
continue;
|
||||||
else if (!command)
|
} else if (!command) {
|
||||||
break;
|
break;
|
||||||
else if (command == -1) {
|
} else if (command == -1) {
|
||||||
log("decodeCharstring: " + charString);
|
log("decodeCharstring: " + charString);
|
||||||
error("Support for Type1 command " + value + " (" + escape + ") is not implemented");
|
error("Support for Type1 command " + value + " (" + escape + ") is not implemented");
|
||||||
}
|
}
|
||||||
@ -1024,24 +1022,19 @@ var Type1Parser = function() {
|
|||||||
} else if (value <= 246) {
|
} else if (value <= 246) {
|
||||||
value = parseInt(value) - 139;
|
value = parseInt(value) - 139;
|
||||||
} else if (value <= 250) {
|
} else if (value <= 250) {
|
||||||
value = ((value - 247) * 256) + parseInt(aStream.getByte()) + 108;
|
value = ((value - 247) * 256) + parseInt(aArray[++i]) + 108;
|
||||||
i++;
|
|
||||||
} else if (value <= 254) {
|
} else if (value <= 254) {
|
||||||
value = -((value - 251) * 256) - parseInt(aStream.getByte()) - 108;
|
value = -((value - 251) * 256) - parseInt(aArray[++i]) - 108;
|
||||||
i++;
|
|
||||||
} else {
|
} else {
|
||||||
var byte = aStream.getByte();
|
var byte = aArray[++i];
|
||||||
var high = (byte >> 1);
|
var high = (byte >> 1);
|
||||||
value = (byte - high) << 24 | aStream.getByte() << 16 |
|
value = (byte - high) << 24 | aArray[++i] << 16 |
|
||||||
aStream.getByte() << 8 | aStream.getByte();
|
aArray[++i] << 8 | aArray[++i];
|
||||||
i += 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
charString.push(value);
|
charString.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var end = Date.now();
|
|
||||||
dump("Time to decode charString of length " + count + " is " + (end - start));
|
|
||||||
return charString;
|
return charString;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1067,16 +1060,16 @@ var Type1Parser = function() {
|
|||||||
if (inSubrs && c == 0x52) {
|
if (inSubrs && c == 0x52) {
|
||||||
length = parseInt(length);
|
length = parseInt(length);
|
||||||
var data = eexecString.slice(i + 3, i + 3 + length);
|
var data = eexecString.slice(i + 3, i + 3 + length);
|
||||||
var encodedSubr = decrypt(data, kCharStringsEncryptionKey, 4).join("");
|
var encodedSubr = decrypt(data, kCharStringsEncryptionKey, 4, true);
|
||||||
var subr = decodeCharString(new StringStream(encodedSubr));
|
var subr = decodeCharString(encodedSubr);
|
||||||
|
|
||||||
subrs.push(subr);
|
subrs.push(subr);
|
||||||
i += 3 + length;
|
i += 3 + length;
|
||||||
} else if (inGlyphs && c == 0x52) {
|
} else if (inGlyphs && c == 0x52) {
|
||||||
length = parseInt(length);
|
length = parseInt(length);
|
||||||
var data = eexecString.slice(i + 3, i + 3 + length);
|
var data = eexecString.slice(i + 3, i + 3 + length);
|
||||||
var encodedCharstring = decrypt(data, kCharStringsEncryptionKey, 4).join("");
|
var encodedCharstring = decrypt(data, kCharStringsEncryptionKey, 4, true);
|
||||||
var subr = decodeCharString(new StringStream(encodedCharstring));
|
var subr = decodeCharString(encodedCharstring);
|
||||||
|
|
||||||
glyphs.push({
|
glyphs.push({
|
||||||
glyph: glyph,
|
glyph: glyph,
|
||||||
@ -1125,12 +1118,11 @@ var CFF = function(aFontName, aFontBBox, aFontFile) {
|
|||||||
fontInfo.name = aFontName;
|
fontInfo.name = aFontName;
|
||||||
fontInfo.bbox = aFontBBox;
|
fontInfo.bbox = aFontBBox;
|
||||||
|
|
||||||
// XXX
|
// XXX This hold the glyph data as if, this should be improved
|
||||||
this.glyphs = fontInfo.charstrings;
|
this.glyphs = fontInfo.charstrings;
|
||||||
|
|
||||||
this.data = this.convertToCFF(fontInfo);
|
this.data = this.convertToCFF(fontInfo);
|
||||||
var end = Date.now();
|
var end = Date.now();
|
||||||
//log("Time to parse font is:" + (end - start));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CFF.prototype = {
|
CFF.prototype = {
|
||||||
@ -1232,13 +1224,22 @@ CFF.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
flattenCharstring: function(aCharstring, aSubrs) {
|
flattenCharstring: function(aCharstring, aSubrs) {
|
||||||
|
var original = aCharstring.slice();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
var obj = aCharstring[i];
|
var obj = aCharstring[i];
|
||||||
if (obj.charAt) {
|
if (obj.charAt) {
|
||||||
switch (obj) {
|
switch (obj) {
|
||||||
case "callsubr":
|
case "callsubr":
|
||||||
var subr = aSubrs[aCharstring[i- 1]].slice();
|
if (aCharstring[i - 1] == 351) {
|
||||||
|
log(original);
|
||||||
|
log(aCharstring);
|
||||||
|
error("...");
|
||||||
|
aCharstring.splice(i - 1, 2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var subr = aSubrs[aCharstring[i - 1]].slice();
|
||||||
if (subr.length > 1) {
|
if (subr.length > 1) {
|
||||||
subr = this.flattenCharstring(subr, aSubrs);
|
subr = this.flattenCharstring(subr, aSubrs);
|
||||||
subr.pop();
|
subr.pop();
|
||||||
|
Loading…
Reference in New Issue
Block a user