Implement roundrect conversion properly.

This commit is contained in:
Jürg Lehni 2012-11-06 08:02:46 -08:00
parent 18b6ad4907
commit 9ad0cb5d63

View file

@ -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,