mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 21:42:30 -05:00
Revert "Wait for other callbacks before load SVG code (#755)"
This reverts commit 2d277581b1
.
This commit is contained in:
parent
e4e316fdbb
commit
dd35871076
1 changed files with 49 additions and 56 deletions
|
@ -27,7 +27,6 @@ class PaperCanvas extends React.Component {
|
|||
bindAll(this, [
|
||||
'setCanvas',
|
||||
'importSvg',
|
||||
'initializeSvg',
|
||||
'maybeZoomToFit',
|
||||
'switchCostume'
|
||||
]);
|
||||
|
@ -172,65 +171,59 @@ class PaperCanvas extends React.Component {
|
|||
performSnapshot(paperCanvas.props.undoSnapshot, Formats.VECTOR_SKIP_CONVERT);
|
||||
return;
|
||||
}
|
||||
item.remove();
|
||||
const itemWidth = item.bounds.width;
|
||||
const itemHeight = item.bounds.height;
|
||||
|
||||
// Without the callback, rasters' load function has not been called yet, and they are
|
||||
// positioned incorrectly
|
||||
window.setTimeout(() => {
|
||||
paperCanvas.initializeSvg(item, rotationCenterX, rotationCenterY, viewBox);
|
||||
}, 0);
|
||||
// Remove viewbox
|
||||
if (item.clipped) {
|
||||
let mask;
|
||||
for (const child of item.children) {
|
||||
if (child.isClipMask()) {
|
||||
mask = child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
item.clipped = false;
|
||||
mask.remove();
|
||||
}
|
||||
|
||||
// Reduce single item nested in groups
|
||||
if (item instanceof paper.Group && item.children.length === 1) {
|
||||
item = item.reduce();
|
||||
}
|
||||
|
||||
ensureClockwise(item);
|
||||
scaleWithStrokes(item, 2, new paper.Point()); // Import at 2x
|
||||
|
||||
if (typeof rotationCenterX !== 'undefined' && typeof rotationCenterY !== 'undefined') {
|
||||
let rotationPoint = new paper.Point(rotationCenterX, rotationCenterY);
|
||||
if (viewBox && viewBox.length >= 2 && !isNaN(viewBox[0]) && !isNaN(viewBox[1])) {
|
||||
rotationPoint = rotationPoint.subtract(viewBox[0], viewBox[1]);
|
||||
}
|
||||
item.translate(new paper.Point(ART_BOARD_WIDTH / 2, ART_BOARD_HEIGHT / 2)
|
||||
.subtract(rotationPoint.multiply(2)));
|
||||
} else {
|
||||
// Center
|
||||
item.translate(new paper.Point(ART_BOARD_WIDTH / 2, ART_BOARD_HEIGHT / 2)
|
||||
.subtract(itemWidth, itemHeight));
|
||||
}
|
||||
if (isGroup(item)) {
|
||||
// Fixes an issue where we may export empty groups
|
||||
for (const child of item.children) {
|
||||
if (isGroup(child) && child.children.length === 0) {
|
||||
child.remove();
|
||||
}
|
||||
}
|
||||
ungroupItems([item]);
|
||||
}
|
||||
|
||||
// Without the callback, the transforms sometimes don't finish applying before the
|
||||
// snapshot is taken.
|
||||
window.setTimeout(
|
||||
() => performSnapshot(paperCanvas.props.undoSnapshot, Formats.VECTOR_SKIP_CONVERT), 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
initializeSvg (item, rotationCenterX, rotationCenterY, viewBox) {
|
||||
const itemWidth = item.bounds.width;
|
||||
const itemHeight = item.bounds.height;
|
||||
|
||||
// Remove viewbox
|
||||
if (item.clipped) {
|
||||
let mask;
|
||||
for (const child of item.children) {
|
||||
if (child.isClipMask()) {
|
||||
mask = child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
item.clipped = false;
|
||||
mask.remove();
|
||||
}
|
||||
|
||||
// Reduce single item nested in groups
|
||||
if (item instanceof paper.Group && item.children.length === 1) {
|
||||
item = item.reduce();
|
||||
}
|
||||
|
||||
ensureClockwise(item);
|
||||
scaleWithStrokes(item, 2, new paper.Point()); // Import at 2x
|
||||
|
||||
if (typeof rotationCenterX !== 'undefined' && typeof rotationCenterY !== 'undefined') {
|
||||
let rotationPoint = new paper.Point(rotationCenterX, rotationCenterY);
|
||||
if (viewBox && viewBox.length >= 2 && !isNaN(viewBox[0]) && !isNaN(viewBox[1])) {
|
||||
rotationPoint = rotationPoint.subtract(viewBox[0], viewBox[1]);
|
||||
}
|
||||
item.translate(new paper.Point(ART_BOARD_WIDTH / 2, ART_BOARD_HEIGHT / 2)
|
||||
.subtract(rotationPoint.multiply(2)));
|
||||
} else {
|
||||
// Center
|
||||
item.translate(new paper.Point(ART_BOARD_WIDTH / 2, ART_BOARD_HEIGHT / 2)
|
||||
.subtract(itemWidth, itemHeight));
|
||||
}
|
||||
paper.project.activeLayer.insertChild(0, item);
|
||||
if (isGroup(item)) {
|
||||
// Fixes an issue where we may export empty groups
|
||||
for (const child of item.children) {
|
||||
if (isGroup(child) && child.children.length === 0) {
|
||||
child.remove();
|
||||
}
|
||||
}
|
||||
ungroupItems([item]);
|
||||
}
|
||||
performSnapshot(this.props.undoSnapshot, Formats.VECTOR_SKIP_CONVERT);
|
||||
}
|
||||
setCanvas (canvas) {
|
||||
this.canvas = canvas;
|
||||
if (this.props.canvasRef) {
|
||||
|
|
Loading…
Reference in a new issue