diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index d6fc0b0f..d36bd553 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -2024,6 +2024,80 @@ function BatchCommand(text) { } }; + var convertToD = function(segList) { + var len = segList.numberOfItems; + var curx = 0, cury = 0; + var d = ""; + for (var i = 0; i < len; ++i) { + var seg = segList.getItem(i); + // if these properties are not in the segment, set them to zero + var x = seg.x || 0, + y = seg.y || 0, + x1 = seg.x1 || 0, + y1 = seg.y1 || 0, + x2 = seg.x2 || 0, + y2 = seg.y2 || 0; + + var type = seg.pathSegType; + switch (type) { + case 1: // z,Z closepath (Z/z) + d += "z"; + break; + case 2: // absolute move (M) + case 4: // absolute line (L) + case 12: // absolute horizontal line (H) + case 14: // absolute vertical line (V) + case 18: // absolute smooth quad (T) + x -= curx; + y -= cury; + case 3: // relative move (m) + case 5: // relative line (l) + case 13: // relative horizontal line (h) + case 15: // relative vertical line (v) + case 19: // relative smooth quad (t) + curx += x; + cury += y; + d += [" ", pathMap[type], x, ",", y].join(''); + break; + case 6: // absolute cubic (C) + x -= curx; x1 -= curx; x2 -= curx; + y -= cury; y1 -= cury; y2 -= cury; + case 7: // relative cubic (c) + curx += x; + cury += y; + d += [" c", x1, ",", y1, " ", x2, ",", y2, " ", x, ",", y].join(''); + break; + case 8: // absolute quad (Q) + x -= curx; x1 -= curx; + y -= cury; y1 -= cury; + case 9: // relative quad (q) + curx += x; + cury += y; + d += [" q", x1, ",", y1, " ", x, ",", y].join(''); + break; + case 10: // absolute elliptical arc (A) + x -= curx; + y -= cury; + case 11: // relative elliptical arc (a) + curx += x; + cury += y; + d += [ "a", seg.r1, ",", seg.r2, " ", seg.angle, " ", + (seg.largeArcFlag ? 1 : 0), " ", (seg.sweepFlag ? 1 : 0), " ", + x, ",", y ].join('') + break; + case 16: // absolute smooth cubic (S) + x -= curx; x2 -= curx; + y -= cury; y2 -= cury; + case 17: // relative smooth cubic (s) + curx += x; + cury += y; + d += [" s", x2, ",", y2, " ", x, ",", y].join(''); + break; + } // switch on path segment type + } // for each segment + return d; + }; + var resetPointGrips = function() { var sr = svgroot.suspendRedraw(100); removeAllPointGripsFromPoly(); @@ -2377,6 +2451,8 @@ function BatchCommand(text) { var poly = current_poly, func = 'createSVGPathSeg' + pathFuncs[type]; var seg = poly[func].apply(poly, pts); poly.pathSegList.replaceItem(seg, index); + // Fyrd: here's where i think it needs to be used +// poly.setAttribute("d", convertToD(poly.pathSegList)); } var addControlPointGrip = function(x, y, source_x, source_y, id, raw_val) {