Skip to content

Commit 31ea4e0

Browse files
committed
Merge pull request #4420 from prometheansacrifice/RemovingCheckSetPresence
Removing set-presence-in-ImageData check from canvas.js
2 parents 5c20d17 + 30e00bc commit 31ea4e0

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/display/canvas.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -507,20 +507,15 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
507507

508508
} else if (imgData.kind === ImageKind.RGBA_32BPP) {
509509
// RGBA, 32-bits per pixel.
510-
var haveSetAndSubarray = 'set' in dest && 'subarray' in src;
511510

512511
for (var i = 0; i < totalChunks; i++) {
513512
var thisChunkHeight =
514513
(i < fullChunks) ? fullChunkHeight : partialChunkHeight;
515514
var elemsInThisChunk = imgData.width * thisChunkHeight * 4;
516-
if (haveSetAndSubarray) {
517-
dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
518-
srcPos += elemsInThisChunk;
519-
} else {
520-
for (var j = 0; j < elemsInThisChunk; j++) {
521-
dest[j] = src[srcPos++];
522-
}
523-
}
515+
516+
dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
517+
srcPos += elemsInThisChunk;
518+
524519
ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
525520
}
526521

web/compatibility.js

+12
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,15 @@ if (typeof PDFJS === 'undefined') {
524524
PDFJS.disableHistory = true;
525525
}
526526
})();
527+
528+
(function checkSetPresenceInImageData() {
529+
if (window.CanvasPixelArray) {
530+
if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
531+
window.CanvasPixelArray.prototype.set = function(arr) {
532+
for (var i = 0, ii = this.length; i < ii; i++) {
533+
this[i] = arr[i];
534+
}
535+
};
536+
}
537+
}
538+
})();

0 commit comments

Comments
 (0)