]> git.parisson.com Git - pdf.js.git/commitdiff
Resolve the char->glyphs mapping issue
authorVivien Nicolas <21@vingtetun.org>
Thu, 16 Jun 2011 01:55:45 +0000 (03:55 +0200)
committerVivien Nicolas <21@vingtetun.org>
Thu, 16 Jun 2011 01:55:45 +0000 (03:55 +0200)
PDFFont.js
pdf.js
test.js

index d106e0b23812b2c82cb53404f0ee5bf02e47f497..48554d9d1123d7a1c0d9b374da3beac83ac7a4e5 100644 (file)
@@ -31,7 +31,7 @@ var fontCount = 0;
 var Fonts = {
   _active: null,
   get active() {
-    return this._active || { encoding: {} };
+    return this._active || { encoding: [] };
   },
 
   set active(aName) {
diff --git a/pdf.js b/pdf.js
index 2b7eb1e1bd908369181fc86e53800ca7e7262a19..fe636bcf966503f93dcd2dbce2b6425855b1f805 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -795,7 +795,6 @@ var Lexer = (function() {
                             }
                         }
 
-                        x = Fonts.unicodeFromCode(x);
                         str += String.fromCharCode(x);
                         break;
                     case '\r':
@@ -811,8 +810,7 @@ var Lexer = (function() {
                     }
                     break;
                 default:
-                    var unicode = Fonts.unicodeFromCode(ch.charCodeAt(0));
-                    str += String.fromCharCode(unicode);
+                    str += ch;
                     break;
                 }
             } while (!done);
@@ -1730,7 +1728,7 @@ var CanvasGraphics = (function() {
             var descriptor = xref.fetch(fontDict.get("FontDescriptor"));
             var fontName = descriptor.get("FontName").name;
             fontName = fontName.replace("+", "_");
-            
+
             var font = Fonts[fontName];
             if (!font) {
                 var fontFile = descriptor.get2("FontFile", "FontFile2");
@@ -1760,7 +1758,7 @@ var CanvasGraphics = (function() {
                       for (var j = 0; j < widths.length; j++) {
                           var index = widths[j];
                           if (index)
-                          charset.push(encoding[j + firstchar]);
+                              charset.push(encoding[j + firstchar]);
                       }
                   }
               }
@@ -2054,7 +2052,12 @@ var CanvasGraphics = (function() {
             this.ctx.scale(1, -1);
             this.ctx.transform.apply(this.ctx, this.current.textMatrix);
 
-            this.ctx.fillText(text, this.current.x, this.current.y);
+            // Replace characters code by glyphs code
+            var glyphs = [];
+            for (var i = 0; i < text.length; i++)
+              glyphs[i] = String.fromCharCode(Fonts.unicodeFromCode(text[i].charCodeAt(0)));
+
+            this.ctx.fillText(glyphs.join(""), this.current.x, this.current.y);
             this.current.x += this.ctx.measureText(text).width;
 
             this.ctx.restore();
diff --git a/test.js b/test.js
index 75b7200027523aef2fea12129d20ee5af30b4907..d0d38687276a27701802a3e013861af2eb6aa9a1 100644 (file)
--- a/test.js
+++ b/test.js
@@ -1,7 +1,7 @@
 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- /
 /* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
 
-var pdfDocument, canvas, pageDisplay, pageNum, pageTimeout;
+var pdfDocument, canvas, pageDisplay, pageNum, pageInterval;
 function load() {
     canvas = document.getElementById("canvas");
     canvas.mozOpaque = true;
@@ -48,7 +48,7 @@ function gotoPage(num) {
 
 function displayPage(num) {
     if (pageNum != num)
-      window.clearTimeout(pageTimeout);
+      window.clearTimeout(pageInterval);
 
     document.getElementById("pageNumber").value = num;
 
@@ -57,7 +57,6 @@ function displayPage(num) {
     var page = pdfDocument.getPage(pageNum = num);
 
     var t1 = Date.now();
-
     var ctx = canvas.getContext("2d");
     ctx.save();
     ctx.fillStyle = "rgb(255, 255, 255)";
@@ -73,17 +72,21 @@ function displayPage(num) {
     page.compile(gfx, fonts);
     var t2 = Date.now();
 
-    var interval = setInterval(function() {
+    // FIXME This need to be replaced by an event
+    pageInterval = setInterval(function() {
         for (var i = 0; i < fonts.length; i++) {
             if (fonts[i].loading)
                 return;
         }
+        var t3 = Date.now();
 
+        clearInterval(pageInterval);
         page.display(gfx);
-        var t3 = Date.now();
+
+        var t4 = Date.now();
+
         var infoDisplay = document.getElementById("info");
-        infoDisplay.innerHTML = "Time to load/compile/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + " ms";
-        clearInterval(interval);
+        infoDisplay.innerHTML = "Time to load/compile/fonts/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + "/" + (t4 - t3) + " ms";
     }, 10);
 }