Skip to content

Commit 0eaabd6

Browse files
committed
Further clean up exporter code.
1 parent e2cf7e1 commit 0eaabd6

9 files changed

Lines changed: 27 additions & 33 deletions

examples/SVG Export/Circle Testing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
var path = new Path.Circle(new Point(50, 50), 25);
2929
path.fillColor = 'red';
3030

31-
var output = SvgExporter.exportProject(paper.project);
31+
var output = SvgExporter.exportProject(project);
3232
console.log(output);
3333
var test = document.getElementById('svg')
3434
test.innerHTML = "";

examples/SVG Export/Empty Path Testing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
var path2 = new Path(segments);
2323
path2.strokeColor = 'yellow';
2424

25-
var output = SvgExporter.exportProject(paper.project);
25+
var output = SvgExporter.exportProject(project);
2626
console.log(output);
2727
var test = document.getElementById('svg')
2828
test.innerHTML = "";

examples/SVG Export/Line Testing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
line3.strokeColor = "yellow";
3838
line3.strokeWidth = "5";
3939

40-
var output = SvgExporter.exportProject(paper.project);
40+
var output = SvgExporter.exportProject(project);
4141
console.log(output);
4242
var test = document.getElementById('svg')
4343
test.innerHTML = "";

examples/SVG Export/Random Path Testing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
var path = new Path.Star(center, points, radius1, radius2);
3636
path.fillColor = 'black';
3737

38-
var output = SvgExporter.exportProject(paper.project);
38+
var output = SvgExporter.exportProject(project);
3939
console.log(output);
4040
var test = document.getElementById('svg')
4141
test.innerHTML = "";

examples/SVG Export/Rect and Attribute Testing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
path4.strokeColor= 'yellow';
5050
path4.fillColor='purple';
5151

52-
var output = SvgExporter.exportProject(paper.project);
52+
var output = SvgExporter.exportProject(project);
5353
console.log(output);
5454
var test = document.getElementById('svg')
5555
test.innerHTML = "";

examples/SVG Export/Text Testing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
c.fillColor = colors[i];
3636
}
3737

38-
var output = SvgExporter.exportProject(paper.project);
38+
var output = SvgExporter.exportProject(project);
3939
var test = document.getElementById('svg')
4040
test.innerHTML = "";
4141
test.appendChild (output);

examples/SVG Export/Transform Test 1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
clonedPath.rotate(angle * i, circlePath.bounds.topLeft);
2626
};
2727

28-
var output = SvgExporter.exportProject(paper.project);
28+
var output = SvgExporter.exportProject(project);
2929
console.log(output);
3030
var test = document.getElementById('svg')
3131
test.innerHTML = "";

examples/SVG Export/Transform Test 2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
copy.strokeColor = 'red';
2222
copy.rotate(-45);
2323
copy.scale(0.5);
24-
var output = SvgExporter.exportProject(paper.project);
24+
var output = SvgExporter.exportProject(project);
2525
var test = document.getElementById('svg')
2626
test.innerHTML = "";
2727
test.appendChild (output);

src/svg/SvgExporter.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -289,44 +289,38 @@ var SvgExporter = this.SvgExporter = new function() {
289289
function pathSetup(path, pointArray, hIArray, hOArray) {
290290
var svgPath = createElement('path');
291291
var pointString = '';
292-
var x1;
293-
var x2;
294-
var y1;
295-
var y2;
296-
var handleOut1;
297-
var handleIn2;
298292
// pointstring is formatted in the way the SVG XML will be reading.
299293
// Namely, a point and the way to traverse to that point.
300294
pointString += 'M' + pointArray[0].getX() + ',' + pointArray[0].getY() + ' ';
301295
//Checks 2 points and the angles in between the 2 points
302296
for (i = 0; i < pointArray.length-1; i++) {
303-
x1 = pointArray[i].getX();
304-
y1 = pointArray[i].getY();
305-
x2 = pointArray[i + 1].getX();
306-
y2 = pointArray[i + 1].getY();
307-
handleOut1 = hOArray[i];
308-
handleIn2 = hIArray[i+1];
297+
var x1 = pointArray[i].getX(),
298+
y1 = pointArray[i].getY(),
299+
x2 = pointArray[i + 1].getX(),
300+
y2 = pointArray[i + 1].getY(),
301+
handleOut1 = hOArray[i],
302+
handleIn2 = hIArray[i+1];
309303
if (handleOut1.getX() == 0 && handleOut1.getY() == 0 && handleIn2.getX() == 0 && handleIn2.getY() == 0) {
310304
// L is lineto, moving to a point with drawing
311305
pointString+= 'L' + x2 + ',' + y2 + ' ';
312306
} else {
313307
// c is curveto, relative: handleOut, handleIn - endpoint, endpoint - startpoint
314-
pointString+= 'c' + (handleOut1.getX()) + ',' + (handleOut1.getY()) + ' ';
315-
pointString+= (x2 - x1 + handleIn2.getX()) + ',' + (y2 - y1 + handleIn2.getY()) + ' ';
316-
pointString+= (x2 - x1) + ',' + (y2-y1) + ' ';
308+
pointString += 'c' + (handleOut1.getX()) + ',' + (handleOut1.getY()) + ' ';
309+
pointString += (x2 - x1 + handleIn2.getX()) + ',' + (y2 - y1 + handleIn2.getY()) + ' ';
310+
pointString += (x2 - x1) + ',' + (y2 - y1) + ' ';
317311
}
318312
}
319313
if (!hOArray[hOArray.length - 1].equals([0, 0]) && !hIArray[0].equals([0, 0])) {
320-
handleOut1 = hOArray[hOArray.length - 1];
321-
handleIn2 = hIArray[0];
322-
// Bezier curve from last point to first
323-
x1 = pointArray[pointArray.length - 1].getX();
324-
y1 = pointArray[pointArray.length - 1].getY();
325-
x2 = pointArray[0].getX();
326-
y2 = pointArray[0].getY();
327-
pointString+= 'c' + (handleOut1.getX()) + ',' + (handleOut1.getY()) + ' ';
328-
pointString+= (x2 - x1 + handleIn2.getX()) + ',' + (y2 - y1 + handleIn2.getY()) + ' ';
329-
pointString+= (x2 - x1) + ',' + (y2-y1) + ' ';
314+
var handleOut1 = hOArray[hOArray.length - 1],
315+
handleIn2 = hIArray[0],
316+
// Bezier curve from last point to first
317+
x1 = pointArray[pointArray.length - 1].getX(),
318+
y1 = pointArray[pointArray.length - 1].getY(),
319+
x2 = pointArray[0].getX(),
320+
y2 = pointArray[0].getY();
321+
pointString += 'c' + (handleOut1.getX()) + ',' + (handleOut1.getY()) + ' ';
322+
pointString += (x2 - x1 + handleIn2.getX()) + ',' + (y2 - y1 + handleIn2.getY()) + ' ';
323+
pointString += (x2 - x1) + ',' + (y2 - y1) + ' ';
330324
}
331325
if (path._closed) {
332326
// z implies a closed path, connecting the first and last points

0 commit comments

Comments
 (0)