Add a debug writeToFile function and remove aggregations for Type2 fonts

This commit is contained in:
Vivien Nicolas 2011-06-10 18:38:57 +02:00
parent da69361ae0
commit 4191485e1f
2 changed files with 39 additions and 39 deletions

View File

@ -729,24 +729,18 @@ var Type1Parser = function(aAsciiStream, aBinaryStream) {
error(obj + " parsing is not implemented (yet)");
break;
case "vstem3":
operandStack.push("vstem");
break;
case "vstem":
//log(obj + " is not converted (yet?)");
operandStack.push("vstem");
break;
case "closepath":
case "return":
break;
case "hlineto":
case "vlineto":
case "rlineto":
case "rrcurveto":
aggregateCommand(obj);
case "vstem3":
case "vstem":
operandStack.push("vstem");
break;
case "hstem":
case "hstem3":
operandStack.push("hstem");
break;
case "rmoveto":
@ -763,20 +757,6 @@ var Type1Parser = function(aAsciiStream, aBinaryStream) {
operandStack.push("rmoveto");
break;
case "hstem":
case "hstem3":
var dy = operandStack.pop();
var y = operandStack.pop();
if (operandStack.peek() == "hstem" ||
operandStack.peek() == "hstem3")
operandStack.pop();
operandStack.push(y - lastPoint);
lastPoint = y + dy;
operandStack.push(dy);
operandStack.push("hstem");
break;
case "callsubr":
var index = operandStack.pop();
@ -960,10 +940,7 @@ Type1Font.prototype = {
var charset = [
0x00
];
var limit = 30;
for (var glyph in charstrings.map) {
if (!limit--)
break;
var index = CFFStrings.indexOf(glyph);
var bytes = integerToBytes(index, 2);
charset.push(bytes[0]);
@ -990,16 +967,14 @@ Type1Font.prototype = {
"rrcurveto": 8,
"endchar": 14,
"rmoveto": 21,
"hmoveto": 22,
"vhcurveto": 30,
"hvcurveto": 31,
};
// Encode the glyph and add it to the FUX
var r = [[0x40, 0xEA]];
var limit = 30;
for (var glyph in glyphs) {
if (!limit--)
break;
var data = glyphs[glyph].slice();
var charstring = [];
for (var i = 0; i < data.length; i++) {
@ -1060,16 +1035,18 @@ Type1Font.prototype = {
var file = new Uint8Array(cff, 0, currentOffset);
var parser = new Type2Parser();
log("parse");
parser.parse(new Stream(file));
var file64 = Base64Encoder.encode(file);
console.log(file64);
log("==================== debug ====================");
log("== parse");
parser.parse(new Stream(file));
var data = [];
for (var i = 0; i < currentOffset; i++)
data.push(cff[i]);
log(data);
log("== write to file");
writeToFile(data, "/tmp/pdf.js.cff");
},
createCFFIndexHeader: function(aObjects, aIsByte) {

View File

@ -349,3 +349,26 @@ var cffData = xhr.mozResponseArrayBuffer || xhr.mozResponse ||
xhr.responseArrayBuffer || xhr.response;
var cff = new Type2Parser("titi.cff");
//cff.parse(new Stream(cffData));
/**
* Write to a file (works only on Firefox in privilege mode");
*/
function writeToFile(aBytes, aFilePath) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var Cc = Components.classes,
Ci = Components.interfaces;
var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile);
file.initWithPath(aFilePath);
var stream = Cc["@mozilla.org/network/file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
stream.init(file, 0x04 | 0x08 | 0x20, 0600, 0);
var bos = Cc["@mozilla.org/binaryoutputstream;1"]
.createInstance(Ci.nsIBinaryOutputStream);
bos.setOutputStream(stream);
bos.writeByteArray(aBytes, aBytes.length);
stream.close();
};