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

View File

@ -349,3 +349,26 @@ var cffData = xhr.mozResponseArrayBuffer || xhr.mozResponse ||
xhr.responseArrayBuffer || xhr.response; xhr.responseArrayBuffer || xhr.response;
var cff = new Type2Parser("titi.cff"); var cff = new Type2Parser("titi.cff");
//cff.parse(new Stream(cffData)); //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();
};