Open pulse-kostis opened 8 years ago
I found a workaround that creates a new path and add the segments from the existing(source) path.
`function pasteSelection() { if (clipboard == null) return;
deselectAll();
var items = [];
for (var i = 0; i < clipboard.length; i++) {
var content = clipboard[i];
var item = paper.Base.importJSON(content.json);
if (item) {
item.selected = true;
items.push(item);
}
}
// Center pasted items to center of the view
var bounds = null;
for (var i = 0; i < items.length; i++) {
if (bounds == null)
bounds = items[i].bounds.clone();
else
bounds = bounds.unite(items[i].bounds);
}
if (bounds) {
var delta = paper.view.center.subtract(bounds.center);
for (var i = 0; i < items.length; i++) {
var cloned = new paper.Path();
for (var t = 0; t < items[i].segments.length; t++) {
cloned.add(items[i].segments[t]);
}
cloned.strokeColor = 'black';
cloned.closed = true;
cloned.strokeWidth = items[i].strokeWidth;
cloned.position = items[i].position.add(delta);
cloned.strokeScaling = false;
console.log(cloned.strokeWidth);
console.log(items[i].strokeWidth);
}
}
undo.snapshot("Paste");
updateSelectionState();
paper.project.view.update();
}`
It works but i am not sure if this breaks something else.
And a better one:
function pasteSelection() { if (clipboard == null) return;
deselectAll();
var items = [];
for (var i = 0; i < clipboard.length; i++) {
var content = clipboard[i];
var item = paper.Base.importJSON(content.json);
if (item) {
item.selected = true;
items.push(item);
}
}
// Center pasted items to center of the view
var bounds = null;
for (var i = 0; i < items.length; i++) {
if (bounds == null)
bounds = items[i].bounds.clone();
else
bounds = bounds.unite(items[i].bounds);
}
if (bounds) {
var delta = paper.view.center.subtract(bounds.center);
for (var i = 0; i < items.length; i++) {
var cloned = new paper.Path();
for (var t = 0; t < items[i].segments.length; t++) {
cloned.add(items[i].segments[t]);
}
cloned.strokeColor = items[i].strokeColor;
cloned.closed = items[i].closed;
cloned.fillColor = items[i].fillColor;
cloned.strokeWidth = items[i].strokeWidth;
cloned.position = items[i].position.add(delta);
cloned.strokeScaling = items[i].strokeScaling;
cloned.selected = true;
}
}
undo.snapshot("Paste");
updateSelectionState();
paper.project.view.update();
}
It is weird that the following didn't work:
var cloned = new paper.Path();
cloned = items[i].clone();
and avoid the properties assignment.
Hi, I use paperjs 0.9.25 in your example and I am not able to paste things. Do you know what I need to change so as it can work with 0.9.25?
Thanks