Skip to content

Commit

Permalink
Revert "Wait for other callbacks before load SVG code (#755)"
Browse files Browse the repository at this point in the history
This reverts commit 2d27758.
  • Loading branch information
paulkaplan authored Nov 9, 2018
1 parent e4e316f commit dd35871
Showing 1 changed file with 45 additions and 52 deletions.
97 changes: 45 additions & 52 deletions src/containers/paper-canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class PaperCanvas extends React.Component {
bindAll(this, [
'setCanvas',
'importSvg',
'initializeSvg',
'maybeZoomToFit',
'switchCostume'
]);
Expand Down Expand Up @@ -172,64 +171,58 @@ 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);
}
});
}
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;
// Remove viewbox
if (item.clipped) {
let mask;
for (const child of item.children) {
if (child.isClipMask()) {
mask = child;
break;
}
}
item.clipped = false;
mask.remove();
}
}
item.clipped = false;
mask.remove();
}

// Reduce single item nested in groups
if (item instanceof paper.Group && item.children.length === 1) {
item = item.reduce();
}
// 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
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();
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);
}
ungroupItems([item]);
}
performSnapshot(this.props.undoSnapshot, Formats.VECTOR_SKIP_CONVERT);
});
}
setCanvas (canvas) {
this.canvas = canvas;
Expand Down

0 comments on commit dd35871

Please sign in to comment.