Fix issue with pasting vector into bitmap

This commit is contained in:
DD Liu 2018-06-28 17:00:44 -04:00
parent e2cc5e46b0
commit e215b8a9b8
2 changed files with 21 additions and 4 deletions

View file

@ -198,12 +198,23 @@ class ModeTools extends React.Component {
clearSelection(this.props.clearSelectedItems); clearSelection(this.props.clearSelectedItems);
if (this.props.clipboardItems.length > 0) { if (this.props.clipboardItems.length > 0) {
let items = [];
for (let i = 0; i < this.props.clipboardItems.length; i++) { for (let i = 0; i < this.props.clipboardItems.length; i++) {
const item = paper.Base.importJSON(this.props.clipboardItems[i]); const item = paper.Base.importJSON(this.props.clipboardItems[i]);
if (item) { 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); const placedItem = paper.project.getActiveLayer().addChild(item);
placedItem.selected = true;
placedItem.position.x += 10 * this.props.pasteOffset; placedItem.position.x += 10 * this.props.pasteOffset;
placedItem.position.y += 10 * this.props.pasteOffset; placedItem.position.y += 10 * this.props.pasteOffset;
} }

View file

@ -135,7 +135,9 @@ class SelectTool extends paper.Tool {
if (Math.abs(decomposed.scaling.x) < 1 && Math.abs(decomposed.scaling.y) < 1 && if (Math.abs(decomposed.scaling.x) < 1 && Math.abs(decomposed.scaling.y) < 1 &&
decomposed.scaling.x !== 0 && decomposed.scaling.y !== 0) { decomposed.scaling.x !== 0 && decomposed.scaling.y !== 0) {
item.canvas = scaleBitmap(item.canvas, decomposed.scaling); item.canvas = scaleBitmap(item.canvas, decomposed.scaling);
if (item.data && item.data.expanded) {
item.data.expanded.canvas = scaleBitmap(item.data.expanded.canvas, decomposed.scaling); item.data.expanded.canvas = scaleBitmap(item.data.expanded.canvas, decomposed.scaling);
}
// Remove the scale from the item's matrix // Remove the scale from the item's matrix
item.matrix.append( item.matrix.append(
new paper.Matrix().scale(new paper.Point(1 / decomposed.scaling.x, 1 / decomposed.scaling.y))); 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 // Draw image onto mask
const m = item.matrix; const m = item.matrix;
context.transform(m.a, m.b, m.c, m.d, m.tx, m.ty); 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); let canvas = item.canvas;
context.drawImage(item.data.expanded.canvas, 0, 0); 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 // Draw temp canvas onto raster layer
getRaster().drawImage(tmpCanvas, new paper.Point()); getRaster().drawImage(tmpCanvas, new paper.Point());