diff --git a/src/containers/mode-tools.jsx b/src/containers/mode-tools.jsx index fddbcfa2..d252e38c 100644 --- a/src/containers/mode-tools.jsx +++ b/src/containers/mode-tools.jsx @@ -198,12 +198,23 @@ class ModeTools extends React.Component { clearSelection(this.props.clearSelectedItems); if (this.props.clipboardItems.length > 0) { + let items = []; for (let i = 0; i < this.props.clipboardItems.length; i++) { const item = paper.Base.importJSON(this.props.clipboardItems[i]); if (item) { - item.selected = true; + items.push(item); } + } + if (!items.length) return; + // If pasting a group or non-raster to bitmap, rasterize firsts + if (isBitmap(this.props.format) && !(items.length === 1 && items[0] instanceof paper.Raster)) { + const group = new paper.Group(items); + items = [group.rasterize()]; + group.remove(); + } + for (const item of items) { const placedItem = paper.project.getActiveLayer().addChild(item); + placedItem.selected = true; placedItem.position.x += 10 * this.props.pasteOffset; placedItem.position.y += 10 * this.props.pasteOffset; } diff --git a/src/helper/bit-tools/select-tool.js b/src/helper/bit-tools/select-tool.js index 73699799..b6e5d0be 100644 --- a/src/helper/bit-tools/select-tool.js +++ b/src/helper/bit-tools/select-tool.js @@ -135,7 +135,9 @@ class SelectTool extends paper.Tool { if (Math.abs(decomposed.scaling.x) < 1 && Math.abs(decomposed.scaling.y) < 1 && decomposed.scaling.x !== 0 && decomposed.scaling.y !== 0) { item.canvas = scaleBitmap(item.canvas, decomposed.scaling); - item.data.expanded.canvas = scaleBitmap(item.data.expanded.canvas, decomposed.scaling); + if (item.data && item.data.expanded) { + item.data.expanded.canvas = scaleBitmap(item.data.expanded.canvas, decomposed.scaling); + } // Remove the scale from the item's matrix item.matrix.append( new paper.Matrix().scale(new paper.Point(1 / decomposed.scaling.x, 1 / decomposed.scaling.y))); @@ -155,8 +157,12 @@ class SelectTool extends paper.Tool { // Draw image onto mask const m = item.matrix; context.transform(m.a, m.b, m.c, m.d, m.tx, m.ty); - context.transform(1, 0, 0, 1, -item.data.expanded.canvas.width / 2, -item.data.expanded.canvas.height / 2); - context.drawImage(item.data.expanded.canvas, 0, 0); + let canvas = item.canvas; + if (item.data && item.data.expanded) { + canvas = item.data.expanded.canvas; + } + context.transform(1, 0, 0, 1, -canvas.width / 2, -canvas.height / 2); + context.drawImage(canvas, 0, 0); // Draw temp canvas onto raster layer getRaster().drawImage(tmpCanvas, new paper.Point());