mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Implement roundrect conversion properly.
This commit is contained in:
parent
18b6ad4907
commit
9ad0cb5d63
1 changed files with 12 additions and 10 deletions
|
@ -119,17 +119,19 @@ var SvgExporter = this.SvgExporter = new function() {
|
||||||
// for the rounded rectangle
|
// for the rounded rectangle
|
||||||
var width = getDistance(segments, 1, 6),
|
var width = getDistance(segments, 1, 6),
|
||||||
height = getDistance(segments, 0, 3),
|
height = getDistance(segments, 0, 3),
|
||||||
point = path.getBounds().getTopLeft(),
|
// Subtract side lengths from total width and divide by 2 to get
|
||||||
dx2 = getDistance(segments, 0, 7),
|
// corner radius size
|
||||||
dy2 = getDistance(segments, 1, 2),
|
rx = (width - getDistance(segments, 0, 7)) / 2,
|
||||||
dx3 = (width - dx2) / 2,
|
ry = (height - getDistance(segments, 1, 2)) / 2,
|
||||||
dy3 = (height - dy2) / 2,
|
// Calculate topLeft corner point, by using sides vectors and
|
||||||
point = new Point((segments[3]._point._x - dx3), (segments[2]._point._y - dy3)),
|
// subtracting normalized rx vector to calculate arc corner.
|
||||||
rx = segments[3]._point._x - point.x,
|
left = segments[3]._point, // top-left side point
|
||||||
ry = segments[2]._point._y - point.y;
|
right = segments[4]._point, // top-right side point
|
||||||
|
point = left.subtract(right.subtract(left).normalize(rx))
|
||||||
|
.rotate(-angle, path.getPosition());
|
||||||
attrs = {
|
attrs = {
|
||||||
x: point._x,
|
x: point.x,
|
||||||
y: point._y,
|
y: point.y,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
rx: rx,
|
rx: rx,
|
||||||
|
|
Loading…
Reference in a new issue