]> git.parisson.com Git - pdf.js.git/commitdiff
Add a debug writeToFile function and remove aggregations for Type2 fonts
authorVivien Nicolas <21@vingtetun.org>
Fri, 10 Jun 2011 16:38:57 +0000 (18:38 +0200)
committerVivien Nicolas <21@vingtetun.org>
Fri, 10 Jun 2011 16:38:57 +0000 (18:38 +0200)
PDFFont.js
PDFFontUtils.js

index e3ddd213d413a38d55ae57c4dd930baf21c64d19..b81b2b2f459b8ecdca595bb4f1eff9583c611993 100644 (file)
@@ -729,24 +729,18 @@ var Type1Parser = function(aAsciiStream, aBinaryStream) {
             error(obj + " parsing is not implemented (yet)");
             break;
 
-          case "vstem3":
-            operandStack.push("vstem");
+          case "closepath":
+          case "return":
             break;
 
+          case "vstem3":
           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 "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) {
index 16d1150ab87eb7367dae1638453da0e8d28bf8dc..e3b6a5a07d1814dc40b8cea091c06a9f1f3fa77c 100644 (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();
+ };
+