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;
var id;
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) {
if (svgData.charAt(0)=='<') {
setFromSvgFileData(svgData);
} else {
setFromSvgPathDescription(svgData);
}
removeShortPaths();
path.alignCorner();
}
function setFromSvgFileData(svgData) {
if (!svgData) svgData = "";
else if (typeof(svgData)!='string') svgData = "";
// else if (svgData.indexOf("CDATA")==-1) svgData = ""; //only accept doodles with CDATA inside containing transforms
else svgData = svgData.split('d="')[1].split('"')[0];
setFromSvgPathDescription(svgData);
}
function getSvgFileData() {
return '';
}
function setFromSvgPathDescription(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 (firstSpaceminPoints && 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;
}
function setId(_id) {
id = _id;
}
function getId() {
return id;
}
return {
getPath: getPath,
setPath: setPath,
getTransformedPath: getTransformedPath,
getSettings: getSettings,
setFromSvgPathDescription: setFromSvgPathDescription,
getSvgPathDescription: getSvgPathDescription,
getSvgFileData: getSvgFileData,
getHeight: getHeight,
getRotation: getRotation,
getTwist: getTwist,
getScaleFunction: getScaleFunction,
getScale: getScale,
setScale: setScale,
getOffset: getOffset,
setOffset: setOffset,
setId: setId,
getId: getId,
}
}