]> git.parisson.com Git - pdf.js.git/commitdiff
skeleton of image drawing
authorChris Jones <jones.chris.g@gmail.com>
Thu, 2 Jun 2011 23:27:56 +0000 (18:27 -0500)
committerChris Jones <jones.chris.g@gmail.com>
Thu, 2 Jun 2011 23:27:56 +0000 (18:27 -0500)
pdf.js
test.html

diff --git a/pdf.js b/pdf.js
index 061be93c5f6d2838a01aebdb32072e02689c7d94..dbceac9fe096ccab90e7e43ea8597675aea3ab2f 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -2024,6 +2024,8 @@ var IDENTITY_MATRIX = [ 1, 0, 0, 1, 0, 0 ];
 // However, PDF needs a bit more state, which we store here.
 var CanvasExtraState = (function() {
     function constructor() {
+        // Are soft masks and alpha values shapes or opacities?
+        this.alphaIsShape = false;
         this.fontSize = 0.0;
         this.textMatrix = IDENTITY_MATRIX;
         // Current point (in user coordinates)
@@ -2358,12 +2360,7 @@ var CanvasGraphics = (function() {
             var type = xobj.dict.get("Subtype");
             assertWellFormed(IsName(type), "XObject should have a Name subtype");
             if ("Image" == type.name) {
-                var magic = "";
-                for (var i = 0; i < 8; ++i)
-                    magic += xobj.bytes[i].toString(16) +" ";
-                console.log("Image magic bytes: "+ magic);
-
-                TODO("Image XObjects");
+                this.paintImageXObject(xobj);
             } else if ("Form" == type.name) {
                 this.paintFormXObject(xobj);
             } else if ("PS" == type.name) {
@@ -2393,6 +2390,40 @@ var CanvasGraphics = (function() {
             this.restore();
         },
 
+        paintImageXObject: function(image) {
+            this.save();
+
+            // TODO cache rendered images?
+            var w = image.dict.get("Width");
+            var h = image.dict.get("Height");
+            var tmpCanvas = document.createElement("canvas");
+            tmpCanvas.height = w;
+            tmpCanvas.width = h;
+            var tmpCtx = tmpCanvas.getContext("2d");
+            var imgData = tmpCtx.getImageData(0, 0, w, h);
+            var pixels = imgData.data;
+
+            var alpha = 25;
+            if (image.dict.has("SMask"))
+                // Specifies either a shape or opacity mask to be
+                // applied to the image samples
+                TODO("SMask");
+
+            for (var i = 0; i < 4 * w * h; ++i) {
+                // TODO blend if SMask is a mask image
+                if (3 === i % 4) {
+                    pixels[i] = alpha;
+                } else {
+                    pixels[i] = image.getChar();
+                }
+            }
+            tmpCtx.putImageData(imgData, 0, 0);
+
+            this.ctx.drawImage(tmpCanvas, 0, 0);
+
+            this.restore();
+        },
+
         // Helper functions
 
         consumePath: function() {
index 0d7d8ce8e80ce9fc3d1c167533c987f5ec7165d4..10a35e16359074aa95a454d965a725d3cf488d4e 100644 (file)
--- a/test.html
+++ b/test.html
@@ -41,7 +41,6 @@ function load() {
     pageDisplay = document.getElementById("pageNumber");
     infoDisplay = document.getElementById("info");
     open("uncompressed.tracemonkey-pldi-09.pdf");
-//    open("uncompressed.report.pdf");
 }
 
 function open(url) {