generalised the function "create_svg_element_by_json()"
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@5 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
a6d1542d1c
commit
196b2b47cf
96
blanksvg.js
96
blanksvg.js
|
@ -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,6 +77,7 @@ signature_started = 0 ;
|
||||||
|
|
||||||
create_svg_element_by_json({
|
create_svg_element_by_json({
|
||||||
"element": "ellipse",
|
"element": "ellipse",
|
||||||
|
"Attr": {
|
||||||
"cx": (freehandcircle_min_x + freehandcircle_max_x ) / 2,
|
"cx": (freehandcircle_min_x + freehandcircle_max_x ) / 2,
|
||||||
"cy": (freehandcircle_min_y + freehandcircle_max_y ) / 2,
|
"cy": (freehandcircle_min_y + freehandcircle_max_y ) / 2,
|
||||||
"rx": (freehandcircle_max_x - freehandcircle_min_x ) / 2 + "px",
|
"rx": (freehandcircle_max_x - freehandcircle_min_x ) / 2 + "px",
|
||||||
|
@ -84,13 +85,14 @@ signature_started = 0 ;
|
||||||
"id": "ellipse_" + ellipse_num,
|
"id": "ellipse_" + ellipse_num,
|
||||||
"fill": current_draw_element_fill,
|
"fill": current_draw_element_fill,
|
||||||
"stroke": current_draw_element_stroke,
|
"stroke": current_draw_element_stroke,
|
||||||
"strokeWidth": current_draw_element_stroke_width
|
"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",
|
||||||
|
"Attr": {
|
||||||
"d": d_attr,
|
"d": d_attr,
|
||||||
"id": "path_" + path_num,
|
"id": "path_" + path_num,
|
||||||
"fill": "none",
|
"fill": "none",
|
||||||
"stroke": current_draw_element_stroke,
|
"stroke": current_draw_element_stroke,
|
||||||
"strokeWidth": current_draw_element_stroke_width
|
"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",
|
||||||
|
"Attr": {
|
||||||
"d": d_attr,
|
"d": d_attr,
|
||||||
"id": "path_" + path_num,
|
"id": "path_" + path_num,
|
||||||
"fill": "none",
|
"fill": "none",
|
||||||
"stroke": current_draw_element_stroke,
|
"stroke": current_draw_element_stroke,
|
||||||
"strokeWidth": current_draw_element_stroke_width
|
"stroke-width": current_draw_element_stroke_width
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -142,6 +148,7 @@ function fun_mouseDOWN(evt)
|
||||||
rect_y = y ;
|
rect_y = y ;
|
||||||
create_svg_element_by_json({
|
create_svg_element_by_json({
|
||||||
"element": "rect",
|
"element": "rect",
|
||||||
|
"Attr": {
|
||||||
"x": x,
|
"x": x,
|
||||||
"y": y,
|
"y": y,
|
||||||
"width": "1px",
|
"width": "1px",
|
||||||
|
@ -149,7 +156,8 @@ function fun_mouseDOWN(evt)
|
||||||
"id": "rect_" + rect_num,
|
"id": "rect_" + rect_num,
|
||||||
"fill": current_draw_element_fill,
|
"fill": current_draw_element_fill,
|
||||||
"stroke": current_draw_element_stroke,
|
"stroke": current_draw_element_stroke,
|
||||||
"strokeWidth": current_draw_element_stroke_width
|
"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",
|
||||||
|
"Attr": {
|
||||||
"x1": x,
|
"x1": x,
|
||||||
"y1": y,
|
"y1": y,
|
||||||
"x2": x + 1 + "px",
|
"x2": x + 1 + "px",
|
||||||
"y2": y + 1 + "px",
|
"y2": y + 1 + "px",
|
||||||
"id": "line_" + line_num,
|
"id": "line_" + line_num,
|
||||||
"stroke": current_draw_element_stroke,
|
"stroke": current_draw_element_stroke,
|
||||||
"strokeWidth": current_draw_element_stroke_width
|
"stroke-width": current_draw_element_stroke_width
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
break
|
break
|
||||||
|
@ -172,6 +182,7 @@ function fun_mouseDOWN(evt)
|
||||||
signature_started = 1 ;
|
signature_started = 1 ;
|
||||||
create_svg_element_by_json({
|
create_svg_element_by_json({
|
||||||
"element": "ellipse",
|
"element": "ellipse",
|
||||||
|
"Attr": {
|
||||||
"cx": x,
|
"cx": x,
|
||||||
"cy": y,
|
"cy": y,
|
||||||
"rx": 1 + "px",
|
"rx": 1 + "px",
|
||||||
|
@ -179,7 +190,8 @@ function fun_mouseDOWN(evt)
|
||||||
"id": "ellipse_" + ellipse_num,
|
"id": "ellipse_" + ellipse_num,
|
||||||
"fill": current_draw_element_fill,
|
"fill": current_draw_element_fill,
|
||||||
"stroke": current_draw_element_stroke,
|
"stroke": current_draw_element_stroke,
|
||||||
"strokeWidth": current_draw_element_stroke_width
|
"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()
|
|
||||||
{
|
|
||||||
|
|
||||||
var shape = SVGDocument.createElementNS(svgns, "path");
|
|
||||||
shape.setAttributeNS(null, "d", d_attr);
|
|
||||||
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)
|
function create_svg_element_by_json(data)
|
||||||
{
|
{
|
||||||
var shape = SVGDocument.createElementNS(svgns, data.element);
|
var shape = SVGDocument.createElementNS(svgns, data.element);
|
||||||
|
for (i in data.Attr) {
|
||||||
|
shape.setAttributeNS(null, i, data.Attr[i]);
|
||||||
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()
|
||||||
|
|
Loading…
Reference in New Issue