generalised the function "create_svg_element_by_json()"

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@5 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Narendra Sisodiya 2009-02-07 13:05:28 +00:00
parent a6d1542d1c
commit 196b2b47cf
1 changed files with 65 additions and 107 deletions

View File

@ -1,6 +1,6 @@
SVGDocument = null; SVGDocument = null;
var svgns = "http://www.w3.org/2000/svg"; var svgns = "http://www.w3.org/2000/svg";
var d_attr = 0 ; var d_attr = "" ;
var signature_started = 0 ; var signature_started = 0 ;
var path_elememt = 0 ; var path_elememt = 0 ;
var path_num = 1 ; var path_num = 1 ;
@ -77,20 +77,22 @@ signature_started = 0 ;
create_svg_element_by_json({ create_svg_element_by_json({
"element": "ellipse", "element": "ellipse",
"cx": (freehandcircle_min_x + freehandcircle_max_x ) / 2, "Attr": {
"cy": (freehandcircle_min_y + freehandcircle_max_y ) / 2, "cx": (freehandcircle_min_x + freehandcircle_max_x ) / 2,
"rx": (freehandcircle_max_x - freehandcircle_min_x ) / 2 + "px", "cy": (freehandcircle_min_y + freehandcircle_max_y ) / 2,
"ry": (freehandcircle_max_y - freehandcircle_min_y ) / 2 + "px", "rx": (freehandcircle_max_x - freehandcircle_min_x ) / 2 + "px",
"id": "ellipse_" + ellipse_num, "ry": (freehandcircle_max_y - freehandcircle_min_y ) / 2 + "px",
"fill": current_draw_element_fill, "id": "ellipse_" + ellipse_num,
"stroke": current_draw_element_stroke, "fill": current_draw_element_fill,
"strokeWidth": current_draw_element_stroke_width "stroke": current_draw_element_stroke,
"stroke-width": current_draw_element_stroke_width
}
}); });
}//switch }//switch
} }//function
function fun_mouseDOWN(evt) function fun_mouseDOWN(evt)
@ -104,14 +106,16 @@ function fun_mouseDOWN(evt)
case "freehandcircle": case "freehandcircle":
d_attr = "M" + x + " " + y + " "; d_attr = "M" + x + " " + y + " ";
signature_started = 1 ; signature_started = 1 ;
//SVG_insert_to_svg();//create element
create_svg_element_by_json({ create_svg_element_by_json({
"element": "path", "element": "path",
"d": d_attr, "Attr": {
"id": "path_" + path_num, "d": d_attr,
"fill": "none", "id": "path_" + path_num,
"stroke": current_draw_element_stroke, "fill": "none",
"strokeWidth": current_draw_element_stroke_width "stroke": current_draw_element_stroke,
"stroke-width": current_draw_element_stroke_width
}
}); });
@ -124,14 +128,16 @@ function fun_mouseDOWN(evt)
case "path": case "path":
d_attr = "M" + x + " " + y + " "; d_attr = "M" + x + " " + y + " ";
signature_started = 1 ; signature_started = 1 ;
//SVG_insert_to_svg();//create element
create_svg_element_by_json({ create_svg_element_by_json({
"element": "path", "element": "path",
"d": d_attr, "Attr": {
"id": "path_" + path_num, "d": d_attr,
"fill": "none", "id": "path_" + path_num,
"stroke": current_draw_element_stroke, "fill": "none",
"strokeWidth": current_draw_element_stroke_width "stroke": current_draw_element_stroke,
"stroke-width": current_draw_element_stroke_width
}
}); });
@ -142,14 +148,16 @@ function fun_mouseDOWN(evt)
rect_y = y ; rect_y = y ;
create_svg_element_by_json({ create_svg_element_by_json({
"element": "rect", "element": "rect",
"x": x, "Attr": {
"y": y, "x": x,
"width": "1px", "y": y,
"height": "1px", "width": "1px",
"id": "rect_" + rect_num, "height": "1px",
"fill": current_draw_element_fill, "id": "rect_" + rect_num,
"stroke": current_draw_element_stroke, "fill": current_draw_element_fill,
"strokeWidth": current_draw_element_stroke_width "stroke": current_draw_element_stroke,
"stroke-width": current_draw_element_stroke_width
}
}); });
break break
@ -158,13 +166,15 @@ function fun_mouseDOWN(evt)
create_svg_element_by_json({ create_svg_element_by_json({
"element": "line", "element": "line",
"x1": x, "Attr": {
"y1": y, "x1": x,
"x2": x + 1 + "px", "y1": y,
"y2": y + 1 + "px", "x2": x + 1 + "px",
"id": "line_" + line_num, "y2": y + 1 + "px",
"stroke": current_draw_element_stroke, "id": "line_" + line_num,
"strokeWidth": current_draw_element_stroke_width "stroke": current_draw_element_stroke,
"stroke-width": current_draw_element_stroke_width
}
}); });
break break
@ -172,14 +182,16 @@ function fun_mouseDOWN(evt)
signature_started = 1 ; signature_started = 1 ;
create_svg_element_by_json({ create_svg_element_by_json({
"element": "ellipse", "element": "ellipse",
"cx": x, "Attr": {
"cy": y, "cx": x,
"rx": 1 + "px", "cy": y,
"ry": 1 + "px", "rx": 1 + "px",
"id": "ellipse_" + ellipse_num, "ry": 1 + "px",
"fill": current_draw_element_fill, "id": "ellipse_" + ellipse_num,
"stroke": current_draw_element_stroke, "fill": current_draw_element_fill,
"strokeWidth": current_draw_element_stroke_width "stroke": current_draw_element_stroke,
"stroke-width": current_draw_element_stroke_width
}
}); });
break break
}//switch }//switch
@ -268,69 +280,15 @@ function max_of(a ,b){
} }
function SVG_insert_to_svg() function create_svg_element_by_json(data)
{ {
var shape = SVGDocument.createElementNS(svgns, data.element);
var shape = SVGDocument.createElementNS(svgns, "path"); for (i in data.Attr) {
shape.setAttributeNS(null, "d", d_attr); shape.setAttributeNS(null, i, data.Attr[i]);
shape.setAttributeNS(null, "id", "path_" + path_num);
shape.setAttributeNS(null, "fill", "none");
shape.setAttributeNS(null, "stroke", "green");
SVGDocument.documentElement.appendChild(shape);
}
function create_svg_element_by_json(data)
{
var shape = SVGDocument.createElementNS(svgns, data.element);
switch (data.element)
{
case "freehandcircle":
case "path":
shape.setAttributeNS(null, "d", data.d_attr);
shape.setAttributeNS(null, "id", data.id);
shape.setAttributeNS(null, "fill", data.fill);
shape.setAttributeNS(null, "stroke", data.stroke);
shape.setAttributeNS(null, "stroke-width", data.strokeWidth);
SVGDocument.documentElement.appendChild(shape);
break
case "rect":
shape.setAttributeNS(null, "x", data.x);
shape.setAttributeNS(null, "y", data.y);
shape.setAttributeNS(null, "width", data.width);
shape.setAttributeNS(null, "height", data.height);
shape.setAttributeNS(null, "id", data.id);
shape.setAttributeNS(null, "fill", data.fill);
shape.setAttributeNS(null, "stroke", data.stroke);
shape.setAttributeNS(null, "stroke-width", data.strokeWidth);
SVGDocument.documentElement.appendChild(shape);
break
case "line":
shape.setAttributeNS(null, "x1", data.x1);
shape.setAttributeNS(null, "x2", data.x2);
shape.setAttributeNS(null, "y1", data.y1);
shape.setAttributeNS(null, "y2", data.y2);
shape.setAttributeNS(null, "id", data.id);
shape.setAttributeNS(null, "stroke", data.stroke);
shape.setAttributeNS(null, "stroke-width", data.strokeWidth);
SVGDocument.documentElement.appendChild(shape);
break
case "ellipse":
shape.setAttributeNS(null, "cx", data.cx);
shape.setAttributeNS(null, "cy", data.cy);
shape.setAttributeNS(null, "rx", data.rx);
shape.setAttributeNS(null, "ry", data.ry);
shape.setAttributeNS(null, "id", data.id);
shape.setAttributeNS(null, "fill", data.fill);
shape.setAttributeNS(null, "stroke", data.stroke);
shape.setAttributeNS(null, "stroke-width", data.strokeWidth);
SVGDocument.documentElement.appendChild(shape);
break
}//switch
} }
SVGDocument.documentElement.appendChild(shape);
}//function
function SVGclear_svg() function SVGclear_svg()