mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Merge pull request #16 from fsih/safariDrawImage
Fix Safari when selection exceeds canvas bounds
This commit is contained in:
commit
9f9f210537
1 changed files with 10 additions and 2 deletions
|
@ -443,8 +443,16 @@ var Raster = Item.extend(/** @lends Raster# */{
|
||||||
getSubCanvas: function(/* rect */) {
|
getSubCanvas: function(/* rect */) {
|
||||||
var rect = Rectangle.read(arguments),
|
var rect = Rectangle.read(arguments),
|
||||||
ctx = CanvasProvider.getContext(rect.getSize());
|
ctx = CanvasProvider.getContext(rect.getSize());
|
||||||
ctx.drawImage(this.getCanvas(), rect.x, rect.y,
|
const clippedStartX = Math.max(0, rect.x);
|
||||||
rect.width, rect.height, 0, 0, rect.width, rect.height);
|
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;
|
return ctx.canvas;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue