0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-22 09:17:56 +01:00

Small svg fix.

Path is now translated so the data can actually be previewed properly.
Change metadata to be put in a single comment.
This commit is contained in:
Wouter R 2013-10-21 23:09:19 +02:00
parent 28c179aa77
commit 9c9086ab91

View File

@ -302,17 +302,17 @@ function onCanvasMouseDown(e) {
function saveToSvg() { function saveToSvg() {
var lastX = 0, lastY = 0, lastIsMove; var lastX = 0, lastY = 0, lastIsMove;
var data = ''; //TODO: change data to an array which is collapsed after the loop?
var svg = ''; var svg = '';
var boundsWidth = doodleBounds[3] - doodleBounds[1]; var boundsWidth = doodleBounds[2] - doodleBounds[0];
var boundsHeight = doodleBounds[2] - doodleBounds[0]; var boundsHeight = doodleBounds[3] - doodleBounds[1];
svg += '<?xml version="1.0" standalone="no"?>\n'; svg += '<?xml version="1.0" standalone="no"?>\n';
svg += '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'; svg += '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n';
svg += '<svg width="' + boundsWidth + '" height="' + boundsHeight + '" version="1.1" xmlns="http://www.w3.org/2000/svg">\n'; svg += '<svg width="' + boundsWidth + '" height="' + boundsHeight + '" version="1.1" xmlns="http://www.w3.org/2000/svg">\n';
svg += '\t<desc>Doodle 3D sketch</desc>\n'; svg += '\t<desc>Doodle 3D sketch</desc>\n';
var data = '';
for (var i = 0; i < _points.length; ++i) { for (var i = 0; i < _points.length; ++i) {
var x = _points[i][0], y = _points[i][1], isMove = _points[i][2]; var x = _points[i][0], y = _points[i][1], isMove = _points[i][2];
var dx = x - lastX, dy = y - lastY; var dx = x - lastX, dy = y - lastY;
@ -329,20 +329,23 @@ function saveToSvg() {
lastIsMove = isMove; lastIsMove = isMove;
} }
svg += '\t<path d="' + data + '" fill="none" stroke="black" stroke-width="1" />\n'; svg += '\t<path transform="translate(' + -doodleBounds[0] + ',' + -doodleBounds[1] + ')" d="' + data + '" fill="none" stroke="black" stroke-width="2" />\n';
var field = 'height', value = numLayers; var makeField = function(k,v) { return k + ': ' + v + '; '; }
svg += '\t<!-- ' + field + ': ' + value + ' -->\n'; svg += '<!-- ' + makeField('height', numLayers) + makeField('outlineShape', VERTICALSHAPE) + makeField('twist', rStep) + '-->\n';
field = 'outlineShape', value = VERTICALSHAPE;
svg += '\t<!-- ' + field + ': ' + value + ' -->\n';
field = 'twist', value = rStep;
svg += '\t<!-- ' + field + ': ' + value + ' -->\n';
svg += '</svg>\n'; svg += '</svg>\n';
return svg; return svg;
} }
function loadFromSvg(svgData) {
//clear out points
//read svg and fill points (and update bounds)
//NOTE: generate the fields comment with some magic value so we can easily detect this while parsing
//update any state necessary to have the canvas/client re-init itself to the new data
}
var prevPoint = {x:-1, y:-1}; var prevPoint = {x:-1, y:-1};
function onCanvasMouseMove(e) { function onCanvasMouseMove(e) {
// console.log("f:onCanvasMouseMove()"); // console.log("f:onCanvasMouseMove()");