[Pkg-javascript-commits] [pdf.js] 157/207: Fixes CanvasPixelArray set polyfill for chrome < 21 (#4974)
David Prévot
taffit at moszumanska.debian.org
Mon Jul 28 15:36:43 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit 9fd6cc7f1ec0c8334c2dc9f9632d1558257c0510
Author: Fabian Lange <lange.fabian at gmail.com>
Date: Tue Jun 24 12:12:17 2014 +0200
Fixes CanvasPixelArray set polyfill for chrome < 21 (#4974)
---
web/compatibility.js | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/web/compatibility.js b/web/compatibility.js
index 400a940..3bb4377 100644
--- a/web/compatibility.js
+++ b/web/compatibility.js
@@ -481,9 +481,9 @@ if (typeof PDFJS === 'undefined') {
}
})();
-// TODO CanvasPixelArray is deprecated; use Uint8ClampedArray
-// once it's supported.
+// Support: IE<11, Chrome<21
(function checkSetPresenceInImageData() {
+ // IE < 11 will use window.CanvasPixelArray which lacks set function.
if (window.CanvasPixelArray) {
if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
window.CanvasPixelArray.prototype.set = function(arr) {
@@ -492,6 +492,25 @@ if (typeof PDFJS === 'undefined') {
}
};
}
+ } else {
+ // Chrome < 21 uses an inaccessible CanvasPixelArray prototype.
+ // Because we cannot feature detect it, we rely on user agent.
+ if (navigator.userAgent.indexOf('Chrom') >= 0) {
+ var versionMatch = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
+ if (versionMatch && parseInt(versionMatch[2]) < 21) {
+ var contextPrototype = window.CanvasRenderingContext2D.prototype;
+ contextPrototype._createImageData = contextPrototype.createImageData;
+ contextPrototype.createImageData = function(w, h) {
+ var imageData = this._createImageData(w, h);
+ imageData.data.set = function(arr) {
+ for (var i = 0, ii = this.length; i < ii; i++) {
+ this[i] = arr[i];
+ }
+ };
+ return imageData;
+ };
+ }
+ }
}
})();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list