mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 21:42:30 -05:00
Merge pull request #984 from adroitwhiz/fix-empty-svg-center
Set rotation center of empty SVGs to (0, 0)
This commit is contained in:
commit
9e70c96044
1 changed files with 10 additions and 2 deletions
|
@ -134,6 +134,14 @@ const UpdateImageHOC = function (WrappedComponent) {
|
||||||
scaleWithStrokes(paper.project.activeLayer, .5, new paper.Point());
|
scaleWithStrokes(paper.project.activeLayer, .5, new paper.Point());
|
||||||
|
|
||||||
const bounds = paper.project.activeLayer.drawnBounds;
|
const bounds = paper.project.activeLayer.drawnBounds;
|
||||||
|
|
||||||
|
// `bounds.x` and `bounds.y` are relative to the top left corner,
|
||||||
|
// but if there is no content in the active layer, they default to 0,
|
||||||
|
// making the "Scratch space" rotation center ((SVG_ART_BOARD_WIDTH / 2), (SVG_ART_BOARD_HEIGHT / 2)),
|
||||||
|
// aka the upper left corner. Special-case this to be (0, 0), which is the center of the art board.
|
||||||
|
const centerX = bounds.width === 0 ? 0 : (SVG_ART_BOARD_WIDTH / 2) - bounds.x;
|
||||||
|
const centerY = bounds.height === 0 ? 0 : (SVG_ART_BOARD_HEIGHT / 2) - bounds.y;
|
||||||
|
|
||||||
this.props.onUpdateImage(
|
this.props.onUpdateImage(
|
||||||
true /* isVector */,
|
true /* isVector */,
|
||||||
paper.project.exportSVG({
|
paper.project.exportSVG({
|
||||||
|
@ -141,8 +149,8 @@ const UpdateImageHOC = function (WrappedComponent) {
|
||||||
bounds: 'content',
|
bounds: 'content',
|
||||||
matrix: new paper.Matrix().translate(-bounds.x, -bounds.y)
|
matrix: new paper.Matrix().translate(-bounds.x, -bounds.y)
|
||||||
}),
|
}),
|
||||||
(SVG_ART_BOARD_WIDTH / 2) - bounds.x,
|
centerX,
|
||||||
(SVG_ART_BOARD_HEIGHT / 2) - bounds.y);
|
centerY);
|
||||||
scaleWithStrokes(paper.project.activeLayer, 2, new paper.Point());
|
scaleWithStrokes(paper.project.activeLayer, 2, new paper.Point());
|
||||||
paper.project.activeLayer.applyMatrix = true;
|
paper.project.activeLayer.applyMatrix = true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue