]> git.parisson.com Git - pdf.js.git/commitdiff
Address review comments: Introduce new CanvasGraphics.putBinaryImageData and make...
authorJulian Viereck <julian.viereck@gmail.com>
Sat, 3 Dec 2011 08:16:40 +0000 (09:16 +0100)
committerJulian Viereck <julian.viereck@gmail.com>
Mon, 5 Dec 2011 17:27:09 +0000 (18:27 +0100)
src/canvas.js
src/core.js
src/fonts.js

index af2555c4e8baab99520b78a5b40f871c1bd2b584..d10469ee90a6c04d254893453836a1a59c6906c3 100644 (file)
@@ -3,29 +3,6 @@
 
 'use strict';
 
-// Some browsers can use UInt8Array directly as imageData.
-PDFJS.FEATURE_CANVAS_UINT_IMAGE_DATA = false;
-if (typeof window !== 'undefined') {
-  window.addEventListener('load', function featureCanvasUIntImgaData() {
-    var canvas = document.createElement('canvas');
-    canvas.width = 1;
-    canvas.height = 1;
-    var ctx = canvas.getContext('2d');
-
-    try {
-      ctx.putImageData({
-        width: 1,
-        height: 1,
-        data: new Uint8Array(4)
-      }, 0, 0);
-    } catch (e) {
-      return;
-    }
-
-    PDFJS.FEATURE_CANVAS_UINT_IMAGE_DATA = true;
-  });
-}
-
 // <canvas> contexts store most of the state we need natively.
 // However, PDF needs a bit more state, which we store here.
 
@@ -810,27 +787,16 @@ var CanvasGraphics = (function canvasGraphics() {
 
       var tmpCanvas = new this.ScratchCanvas(w, h);
       var tmpCtx = tmpCanvas.getContext('2d');
-      var tmpImgData;
-
-      if (PDFJS.FEATURE_CANVAS_UINT_IMAGE_DATA) {
-        tmpImgData = imgData;
-      } else {
-        tmpImgData = tmpCtx.getImageData(0, 0, w, h);
-
-        // Copy over the imageData pixel by pixel.
-        var tmpImgDataPixels = tmpImgData.data;
-        var len = tmpImgDataPixels.length;
-
-        while (len--) {
-          tmpImgDataPixels[len] = imgData.data[len];
-        }
-      }
+      this.putBinaryImageData(tmpCtx, imgData, w, h);
 
-      tmpCtx.putImageData(tmpImgData, 0, 0);
       ctx.drawImage(tmpCanvas, 0, -h);
       this.restore();
     },
 
+    putBinaryImageData: function canvasPutBinaryImageData() {
+      //
+    },
+
     // Marked content
 
     markPoint: function canvasGraphicsMarkPoint(tag) {
@@ -891,3 +857,38 @@ var CanvasGraphics = (function canvasGraphics() {
   return constructor;
 })();
 
+if (!isWorker) {
+  // Feature detection if the browser can use an Uint8Array directly as imgData.
+  var canvas = document.createElement('canvas');
+  canvas.width = 1;
+  canvas.height = 1;
+  var ctx = canvas.getContext('2d');
+
+  try {
+    ctx.putImageData({
+      width: 1,
+      height: 1,
+      data: new Uint8Array(4)
+    }, 0, 0);
+
+    CanvasGraphics.prototype.putBinaryImageData =
+      function CanvasGraphicsPutBinaryImageDataNative(ctx, imgData) {
+        ctx.putImageData(imgData, 0, 0);
+      };
+  } catch (e) {
+    CanvasGraphics.prototype.putBinaryImageData =
+      function CanvasGraphicsPutBinaryImageDataShim(ctx, imgData, w, h) {
+        var tmpImgData = ctx.getImageData(0, 0, w, h);
+
+        // Copy over the imageData pixel by pixel.
+        var tmpImgDataPixels = tmpImgData.data;
+        var len = tmpImgDataPixels.length;
+
+        while (len--) {
+          tmpImgDataPixels[len] = imgData.data[len];
+        }
+
+        ctx.putImageData(tmpImgData, 0, 0);
+      };
+  }
+}
index 3549eb906b6795d70d99572494a2351c66373bbf..5735d7415f3f5344c0d7378405b531f4fa6d02d6 100644 (file)
@@ -5,6 +5,8 @@
 
 var globalScope = (typeof window === 'undefined') ? this : window;
 
+var isWorker = (typeof window == 'undefined');
+
 var ERRORS = 0, WARNINGS = 1, TODOS = 5;
 var verbosity = WARNINGS;
 
index 116bb4dfc71064a1e8f86d092d852628751117ec..3809123f75e8ef48951844ab232c19f1228e9026 100644 (file)
@@ -3,8 +3,6 @@
 
 'use strict';
 
-var isWorker = (typeof window == 'undefined');
-
 /**
  * Maximum time to wait for a font to be loaded by font-face rules.
  */