var Doodle = function(svgData,settings) { var path = new Path(); var height = 10; //in mm var offset = new Point(0,0); var scale = 1; var rotation = 0; var twist = .1; if (settings!=undefined) { if (settings.height!=undefined) height = settings.height; if (settings.twist!=undefined) twist = settings.twist; if (settings.scale!=undefined) scale = settings.scale; if (settings.offset!=undefined) offset = settings.offset; } if (svgData!=undefined) { setFromSvgPathDescription(svgData); removeShortPaths(); //move this to main.js? // offset.x += path.getBoundingBox().getX(); // offset.y += path.getBoundingBox().getY(); path.alignCorner(); //set left-top corner of path boundingbox to 0,0 // scale = 1; // console.log(path.getBoundingBox().getX(),offset); } function setFromSvgPathDescription(svgData) { // if (!svgData) svgData = ""; // else if (typeof(svgData)!='string') svgData = ""; // // else if (svgData.indexOf("CDATA")==-1) svgData = ""; // else svgData = svgData.split('d="')[1].split('"')[0]; // console.log('svgData',svgData); svgData+=' '; //add a trailing space //Parse Path Description var mode = '', x=0, y=0, p=0; var path = new Path(); var skipSpace = function() { while (svgData.charAt(p) == ' ') p++; } var parser = function() { while (true) { skipSpace(); if (p==svgData.length) { return true; } var c = svgData.charAt(p); if (c == 'M' || c == 'm' || c == 'L' || c == 'l') { //new command letter mode = c; } else if (c == '"') { //end of command chain return true; } else { //something else, must be a pair of coordinates... var tx = 0, ty = 0, numberEnd = 0, len = 0; numberEnd = svgData.indexOf(',', p); ////// RC: if instead of a comma a space is used between a pair use that as a separator //var firstSpace = svgData.indexOf(' ', p); //if (firstSpace'; } function removeShortPaths(minLength,minPoints) { if (!minLength) minLength = 10; if (!minPoints) minPoints = 1; path.setPolylines(path.getPolylines().filter(function(polyline) { return polyline.getPoints().length>minPoints && polyline.getPerimeter()>minLength; })); } function getPath() { return path; } function setPath(newPath) { path = newPath } function getSettings() { return settings; } function getHeight() { return height; } function getTwist() { return twist; } function getScale() { return scale; } function setScale(_scale) { scale = _scale; } function getOffset() { return offset; } function setOffset(_offset) { offset = _offset; } function getRotation() { return rotation; } function getScaleFunction(f) { return 1; //Math.sin(f*2*Math.PI)/4+1; } return { getPath: getPath, setPath: setPath, getSettings: getSettings, setFromSvgPathDescription: setFromSvgPathDescription, getSvgPathDescription: getSvgPathDescription, getHeight: getHeight, getRotation: getRotation, getTwist: getTwist, getScaleFunction: getScaleFunction, getScale: getScale, setScale: setScale, getOffset: getOffset, setOffset: setOffset, } }