Skip to content

Commit

Permalink
Merge pull request #4997 from CodingFabian/issue-4974
Browse files Browse the repository at this point in the history
Fixes CanvasPixelArray set polyfill (#4974)
  • Loading branch information
yurydelendik committed Jun 24, 2014
2 parents cd79ac8 + 9fd6cc7 commit b482393
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions web/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
};
}
}
}
})();

Expand Down

0 comments on commit b482393

Please sign in to comment.