From 304657a10425df910a2ba9d8800ec24820eb9761 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Sun, 19 Jan 2014 17:43:27 +0100 Subject: [PATCH] Reindent Svg.js. --- js/Svg.js | 198 +++++++++++++++++++++++++++--------------------------- 1 file changed, 99 insertions(+), 99 deletions(-) diff --git a/js/Svg.js b/js/Svg.js index 87e065b..d61ce96 100644 --- a/js/Svg.js +++ b/js/Svg.js @@ -9,132 +9,132 @@ //SVG validator: http://validator.w3.org/ //SVG viewer: http://svg-edit.googlecode.com/svn/branches/2.6/editor/svg-editor.html function saveToSvg() { - var lastX = 0, lastY = 0, lastIsMove; - var svg = ''; + var lastX = 0, lastY = 0, lastIsMove = false; + var svg = ''; - var boundsWidth = doodleBounds[2] - doodleBounds[0]; - var boundsHeight = doodleBounds[3] - doodleBounds[1]; + var boundsWidth = doodleBounds[2] - doodleBounds[0]; + var boundsHeight = doodleBounds[3] - doodleBounds[1]; - svg += '\n'; - svg += '\n'; - svg += '\n'; - svg += '\tDoodle 3D sketch\n'; + svg += '\n'; + svg += '\n'; + svg += '\n'; + svg += '\tDoodle 3D sketch\n'; - var data = ''; - for (var i = 0; i < _points.length; ++i) { - var x = _points[i][0], y = _points[i][1], isMove = _points[i][2]; - var dx = x - lastX, dy = y - lastY; + var data = ''; + for (var i = 0; i < _points.length; ++i) { + var x = _points[i][0], y = _points[i][1], isMove = _points[i][2]; + var dx = x - lastX, dy = y - lastY; - if (i == 0) - data += 'M'; //emit absolute move on first pair of coordinates - else if (isMove != lastIsMove) - data += isMove ? 'm' : 'l'; + if (i == 0) + data += 'M'; //emit absolute move on first pair of coordinates + else if (isMove != lastIsMove) + data += isMove ? 'm' : 'l'; - data += dx + ',' + dy + ' '; + data += dx + ',' + dy + ' '; - lastX = x; - lastY = y; - lastIsMove = isMove; - } + lastX = x; + lastY = y; + lastIsMove = isMove; + } - svg += '\t\n'; + svg += '\t\n'; - var fields = JSON.stringify({'height': numLayers, 'outlineShape': VERTICALSHAPE, 'twist': rStep}); - svg += '\t\n'; + var fields = JSON.stringify({'height': numLayers, 'outlineShape': VERTICALSHAPE, 'twist': rStep}); + svg += '\t\n'; - svg += '\n'; + svg += '\n'; - return svg; + return svg; } //TODO: use local variables instead of _points,numLayers,VERTICALSHAPE and rStep so we can leave a current doodle in tact if an error occurs while parsing function loadFromSvg(svgData) { - var mode = '', x = 0, y = 0; + var mode = '', x = 0, y = 0; - console.log("loading " + svgData.length + " bytes of data..."); + console.log("loading " + svgData.length + " bytes of data..."); - clearDoodle(); + clearDoodle(); - var p = svgData.indexOf("-->", p); - if (endP == -1) { console.log("loadFromSvg: could not find metadata end-marker"); return false; } - var metaFields = JSON.parse(svgData.substr(p, endP - p)); - //TODO: log error and return false if parsing failed - for (var k in metaFields) { - var v = metaFields[k]; - switch (k) { - case "height": numLayers = v; break; - case "outlineShape": VERTICALSHAPE = v; break; - case "twist": rStep = v; break; - } - } + var endP = svgData.indexOf("]]>-->", p); + if (endP == -1) { console.log("loadFromSvg: could not find metadata end-marker"); return false; } + var metaFields = JSON.parse(svgData.substr(p, endP - p)); + //TODO: log error and return false if parsing failed + for (var k in metaFields) { + var v = metaFields[k]; + switch (k) { + case "height": numLayers = v; break; + case "outlineShape": VERTICALSHAPE = v; break; + case "twist": rStep = v; break; + } + } - renderToImageDataPreview(); + renderToImageDataPreview(); - return true; + return true; }