From 40390f830961f37315ba3b4c649eec664426dab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 6 Nov 2012 07:49:31 -0800 Subject: [PATCH] Make drawCurve() a private function of drawPath(). --- src/svg/SvgExporter.js | 43 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/svg/SvgExporter.js b/src/svg/SvgExporter.js index f38373a2..f3deb9c7 100644 --- a/src/svg/SvgExporter.js +++ b/src/svg/SvgExporter.js @@ -179,37 +179,38 @@ var SvgExporter = this.SvgExporter = new function() { function drawPath(path, segments) { var parts = [], style = path._style; + + function drawCurve(seg1, seg2, skipLine) { + var point1 = seg1._point, + point2 = seg2._point, + handle1 = seg1._handleOut, + handle2 = seg2._handleIn; + if (handle1.isZero() && handle2.isZero()) { + if (!skipLine) { + // L = lineto: moving to a point with drawing + parts.push('L' + formatPoint(point2)); + } + } else { + // c = relative curveto: handle1, handle2 + end - start, end - start + var end = point2.subtract(point1); + parts.push('c' + formatPoint(handle1), + formatPoint(end.add(handle2)), + formatPoint(end)); + } + } + parts.push('M' + formatPoint(segments[0]._point)); for (i = 0; i < segments.length - 1; i++) - drawCurve(parts, segments[i], segments[i + 1], false); + drawCurve(segments[i], segments[i + 1], false); // We only need to draw the connecting curve if it is not a line, and if // the path is cosed and has a stroke color, or if it is filled. if (path._closed && style._strokeColor || style._fillColor) - drawCurve(parts, segments[segments.length - 1], segments[0], true); + drawCurve(segments[segments.length - 1], segments[0], true); if (path._closed) parts.push('z'); return parts.join(' '); } - function drawCurve(parts, seg1, seg2, skipLine) { - var point1 = seg1._point, - point2 = seg2._point, - handle1 = seg1._handleOut, - handle2 = seg2._handleIn; - if (handle1.isZero() && handle2.isZero()) { - if (!skipLine) { - // L = lineto: moving to a point with drawing - parts.push('L' + formatPoint(point2)); - } - } else { - // c = relative curveto: handle1, handle2 + end - start, end - start - var end = point2.subtract(point1); - parts.push('c' + formatPoint(handle1), - formatPoint(end.add(handle2)), - formatPoint(end)); - } - } - function determineAngle(path, segments, type) { // If the object is a circle, ellipse, rectangle, or rounded rectangle, // see if they are placed at an angle.