From e0b6759add3b3aa2b86d7f8d44c75d13e44d57c0 Mon Sep 17 00:00:00 2001 From: DD Liu Date: Thu, 26 Jul 2018 15:08:48 -0400 Subject: [PATCH] Make raster's getSubRaster function allow rectangles that exceed the bounds of the canvas. This fixes Safari, which returns a blank canvas in that case. --- src/item/Raster.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/item/Raster.js b/src/item/Raster.js index fa26da27..d895e768 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -443,8 +443,16 @@ var Raster = Item.extend(/** @lends Raster# */{ getSubCanvas: function(/* rect */) { var rect = Rectangle.read(arguments), ctx = CanvasProvider.getContext(rect.getSize()); - ctx.drawImage(this.getCanvas(), rect.x, rect.y, - rect.width, rect.height, 0, 0, rect.width, rect.height); + const clippedStartX = Math.max(0, rect.x); + const clippedStartY = Math.max(0, rect.y); + const clippedEndX = Math.min(this.getCanvas().width, rect.x + rect.width); + const clippedEndY = Math.min(this.getCanvas().height, rect.y + rect.height); + ctx.drawImage(this.getCanvas(), + clippedStartX, clippedStartY, + clippedEndX - clippedStartX, clippedEndY - clippedStartY, + clippedStartX - rect.x, clippedStartY - rect.y, + clippedEndX - clippedStartX, clippedEndY - clippedStartY + ); return ctx.canvas; },