2009-06-02 11:09:49 +00:00
|
|
|
var svgcanvas = null;
|
2009-06-01 17:35:22 +00:00
|
|
|
|
|
|
|
function svgCanvasInit(event) {
|
2009-06-02 11:09:49 +00:00
|
|
|
svgcanvas = new SvgCanvas(event.target.ownerDocument);
|
|
|
|
svgcanvas.setup(event);
|
2009-06-05 12:23:24 +00:00
|
|
|
parent.SvgCanvas = svgcanvas;
|
2009-06-01 17:35:22 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 21:24:30 +00:00
|
|
|
function SvgCanvas(doc)
|
2009-06-01 17:35:22 +00:00
|
|
|
{
|
|
|
|
|
2009-06-01 21:24:30 +00:00
|
|
|
// private members
|
|
|
|
|
|
|
|
var svgdoc = doc;
|
|
|
|
var svgroot = svgdoc.documentElement;
|
|
|
|
var svgns = "http://www.w3.org/2000/svg";
|
2009-06-02 16:40:33 +00:00
|
|
|
var d_attr = null;
|
|
|
|
var started = false;
|
2009-06-01 21:24:30 +00:00
|
|
|
var obj_num = 1;
|
2009-06-02 16:40:33 +00:00
|
|
|
var start_x = null;
|
|
|
|
var start_y = null;
|
|
|
|
var current_mode = "path";
|
|
|
|
var current_fill = "none";
|
|
|
|
var current_stroke = "black";
|
|
|
|
var current_stroke_width = 1;
|
|
|
|
var current_stroke_style = "none";
|
|
|
|
var current_opacity = 1;
|
2009-06-04 13:43:58 +00:00
|
|
|
var current_stroke_opacity = 1;
|
|
|
|
var current_fill_opacity = 1;
|
2009-06-01 21:24:30 +00:00
|
|
|
var freehand_min_x = null;
|
|
|
|
var freehand_max_x = null;
|
|
|
|
var freehand_min_y = null;
|
|
|
|
var freehand_max_y = null;
|
2009-06-03 08:41:25 +00:00
|
|
|
var selected = null;
|
2009-06-01 21:24:30 +00:00
|
|
|
|
|
|
|
// private functions
|
2009-06-05 12:33:02 +00:00
|
|
|
var getId = function() {
|
|
|
|
return "svg_"+obj_num;
|
|
|
|
}
|
2009-06-01 21:24:30 +00:00
|
|
|
|
|
|
|
var assignAttributes = function(node, attrs) {
|
|
|
|
for (i in attrs) {
|
|
|
|
node.setAttributeNS(null, i, attrs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-02 16:40:33 +00:00
|
|
|
// remove unneeded attributes
|
|
|
|
// makes resulting SVG smaller
|
|
|
|
var cleanupElement = function(element) {
|
|
|
|
if (element.getAttribute('fill-opacity') == '1')
|
|
|
|
element.removeAttribute('fill-opacity');
|
|
|
|
if (element.getAttribute('opacity') == '1')
|
|
|
|
element.removeAttribute('opacity');
|
|
|
|
if (element.getAttribute('stroke') == 'none')
|
|
|
|
element.removeAttribute('stroke');
|
|
|
|
if (element.getAttribute('stroke-dasharray') == 'none')
|
|
|
|
element.removeAttribute('stroke-dasharray');
|
|
|
|
if (element.getAttribute('stroke-opacity') == '1')
|
|
|
|
element.removeAttribute('stroke-opacity');
|
|
|
|
if (element.getAttribute('stroke-width') == '1')
|
|
|
|
element.removeAttribute('stroke-width');
|
|
|
|
}
|
|
|
|
|
|
|
|
var addSvgElementFromJson = function(data) {
|
2009-06-01 21:24:30 +00:00
|
|
|
var shape = svgdoc.createElementNS(svgns, data.element);
|
|
|
|
assignAttributes(shape, data.attr);
|
2009-06-02 16:40:33 +00:00
|
|
|
cleanupElement(shape);
|
2009-06-01 21:24:30 +00:00
|
|
|
svgdoc.documentElement.appendChild(shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
var svgToString = function(elem, indent) {
|
|
|
|
var out = "";
|
|
|
|
if (elem) {
|
|
|
|
var attrs = elem.attributes;
|
|
|
|
var attr;
|
|
|
|
var i;
|
|
|
|
var childs = elem.childNodes;
|
|
|
|
// don't include scripts in output svg
|
|
|
|
if (elem.nodeName == "script") return "";
|
|
|
|
for (i=0; i<indent; i++) out += " ";
|
|
|
|
out += "<" + elem.nodeName;
|
|
|
|
for (i=attrs.length-1; i>=0; i--) {
|
|
|
|
attr = attrs.item(i);
|
|
|
|
// don't include events in output svg
|
|
|
|
if (attr.nodeName == "onload" ||
|
|
|
|
attr.nodeName == "onmousedown" ||
|
|
|
|
attr.nodeName == "onmousemove" ||
|
|
|
|
attr.nodeName == "onmouseup") continue;
|
|
|
|
out += " " + attr.nodeName + "=\"" + attr.nodeValue+ "\"";
|
|
|
|
}
|
|
|
|
if (elem.hasChildNodes()) {
|
|
|
|
out += ">\n";
|
|
|
|
indent++;
|
|
|
|
for (i=0; i<childs.length; i++)
|
|
|
|
{
|
2009-06-02 16:40:33 +00:00
|
|
|
if (childs.item(i).nodeType == 1) { // element node
|
|
|
|
out = out + svgToString(childs.item(i), indent);
|
|
|
|
} else if (childs.item(i).nodeType == 3) { // text node
|
|
|
|
for (j=0; j<indent; j++) out += " ";
|
|
|
|
out += childs.item(i).nodeValue + "\n";
|
2009-06-01 21:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
indent--;
|
|
|
|
for (i=0; i<indent; i++) out += " ";
|
|
|
|
out += "</" + elem.nodeName + ">\n";
|
|
|
|
} else {
|
|
|
|
out += " />\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2009-06-02 12:52:44 +00:00
|
|
|
// public events
|
2009-06-01 21:24:30 +00:00
|
|
|
|
|
|
|
this.mouseDown = function(evt)
|
|
|
|
{
|
|
|
|
var x = evt.pageX;
|
|
|
|
var y = evt.pageY;
|
2009-06-03 08:41:25 +00:00
|
|
|
switch (current_mode) {
|
|
|
|
case "select":
|
|
|
|
started = true;
|
|
|
|
start_x = x;
|
|
|
|
start_y = y;
|
|
|
|
if (evt.target != svgroot)
|
|
|
|
selected = evt.target;
|
|
|
|
addSvgElementFromJson({
|
|
|
|
"element": "rect",
|
|
|
|
"attr": {
|
|
|
|
"x": x,
|
|
|
|
"y": y,
|
|
|
|
"width": 0,
|
|
|
|
"height": 0,
|
2009-06-05 12:33:02 +00:00
|
|
|
"id": getId(),
|
2009-06-03 08:41:25 +00:00
|
|
|
"fill": '#DBEBF9',
|
|
|
|
"stroke": '#CEE2F7',
|
|
|
|
"stroke-width": 1,
|
|
|
|
"fill-opacity": 0.5
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "fhellipse":
|
|
|
|
case "fhrect":
|
|
|
|
case "path":
|
|
|
|
started = true;
|
|
|
|
d_attr = "M" + x + " " + y + " ";
|
|
|
|
addSvgElementFromJson({
|
|
|
|
"element": "path",
|
|
|
|
"attr": {
|
|
|
|
"d": d_attr,
|
2009-06-05 12:33:02 +00:00
|
|
|
"id": getId(),
|
2009-06-03 08:41:25 +00:00
|
|
|
"fill": "none",
|
|
|
|
"stroke": current_stroke,
|
|
|
|
"stroke-width": current_stroke_width,
|
|
|
|
"stroke-dasharray": current_stroke_style,
|
2009-06-04 13:43:58 +00:00
|
|
|
"stroke-opacity": current_stroke_opacity,
|
|
|
|
"opacity": current_opacity / 2
|
2009-06-03 08:41:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
freehand_min_x = x;
|
|
|
|
freehand_max_x = x;
|
|
|
|
freehand_min_y = y;
|
|
|
|
freehand_max_y = y;
|
|
|
|
break;
|
|
|
|
case "square":
|
|
|
|
case "rect":
|
|
|
|
started = true;
|
|
|
|
start_x = x;
|
|
|
|
start_y = y;
|
|
|
|
addSvgElementFromJson({
|
|
|
|
"element": "rect",
|
|
|
|
"attr": {
|
|
|
|
"x": x,
|
|
|
|
"y": y,
|
|
|
|
"width": 0,
|
|
|
|
"height": 0,
|
2009-06-06 13:21:45 +00:00
|
|
|
"id": getId(),
|
2009-06-03 08:41:25 +00:00
|
|
|
"fill": current_fill,
|
|
|
|
"stroke": current_stroke,
|
|
|
|
"stroke-width": current_stroke_width,
|
|
|
|
"stroke-dasharray": current_stroke_style,
|
2009-06-04 13:43:58 +00:00
|
|
|
"stroke-opacity": current_stroke_opacity,
|
|
|
|
"fill-opacity": current_fill_opacity,
|
|
|
|
"opacity": current_opacity / 2
|
2009-06-03 08:41:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "line":
|
|
|
|
started = true;
|
|
|
|
addSvgElementFromJson({
|
|
|
|
"element": "line",
|
|
|
|
"attr": {
|
|
|
|
"x1": x,
|
|
|
|
"y1": y,
|
|
|
|
"x2": x,
|
|
|
|
"y2": y,
|
2009-06-05 12:33:02 +00:00
|
|
|
"id": getId(),
|
2009-06-03 08:41:25 +00:00
|
|
|
"stroke": current_stroke,
|
|
|
|
"stroke-width": current_stroke_width,
|
|
|
|
"stroke-dasharray": current_stroke_style,
|
2009-06-04 13:43:58 +00:00
|
|
|
"stroke-opacity": current_stroke_opacity,
|
|
|
|
"opacity": current_opacity / 2
|
2009-06-03 08:41:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "circle":
|
2009-06-03 15:00:48 +00:00
|
|
|
started = true;
|
|
|
|
addSvgElementFromJson({
|
|
|
|
"element": "circle",
|
|
|
|
"attr": {
|
|
|
|
"cx": x,
|
|
|
|
"cy": y,
|
|
|
|
"r": 0,
|
2009-06-05 12:33:02 +00:00
|
|
|
"id": getId(),
|
2009-06-03 15:00:48 +00:00
|
|
|
"fill": current_fill,
|
|
|
|
"stroke": current_stroke,
|
|
|
|
"stroke-width": current_stroke_width,
|
|
|
|
"stroke-dasharray": current_stroke_style,
|
2009-06-04 13:43:58 +00:00
|
|
|
"stroke-opacity": current_stroke_opacity,
|
|
|
|
"fill-opacity": current_fill_opacity,
|
|
|
|
"opacity": current_opacity / 2
|
2009-06-03 15:00:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
2009-06-03 08:41:25 +00:00
|
|
|
case "ellipse":
|
|
|
|
started = true;
|
|
|
|
addSvgElementFromJson({
|
|
|
|
"element": "ellipse",
|
|
|
|
"attr": {
|
|
|
|
"cx": x,
|
|
|
|
"cy": y,
|
|
|
|
"rx": 0,
|
|
|
|
"ry": 0,
|
2009-06-05 13:20:04 +00:00
|
|
|
"id": getId(),
|
2009-06-03 08:41:25 +00:00
|
|
|
"fill": current_fill,
|
|
|
|
"stroke": current_stroke,
|
|
|
|
"stroke-width": current_stroke_width,
|
|
|
|
"stroke-dasharray": current_stroke_style,
|
2009-06-04 13:43:58 +00:00
|
|
|
"stroke-opacity": current_stroke_opacity,
|
|
|
|
"fill-opacity": current_fill_opacity,
|
|
|
|
"opacity": current_opacity / 2
|
2009-06-03 08:41:25 +00:00
|
|
|
}
|
|
|
|
});
|
2009-06-03 15:00:48 +00:00
|
|
|
break;
|
2009-06-03 08:41:25 +00:00
|
|
|
case "delete":
|
|
|
|
var t = evt.target;
|
|
|
|
if (t == svgroot) return;
|
|
|
|
t.parentNode.removeChild(t);
|
|
|
|
break;
|
2009-06-01 21:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mouseMove = function(evt)
|
|
|
|
{
|
2009-06-02 16:40:33 +00:00
|
|
|
if (!started) return;
|
|
|
|
|
|
|
|
var x = evt.pageX;
|
|
|
|
var y = evt.pageY;
|
2009-06-05 12:33:02 +00:00
|
|
|
var shape = svgdoc.getElementById(getId());
|
2009-06-02 16:40:33 +00:00
|
|
|
switch (current_mode)
|
2009-06-01 21:24:30 +00:00
|
|
|
{
|
2009-06-02 16:40:33 +00:00
|
|
|
case "line":
|
|
|
|
shape.setAttributeNS(null, "x2", x);
|
|
|
|
shape.setAttributeNS(null, "y2", y);
|
|
|
|
break;
|
|
|
|
case "square":
|
|
|
|
var size = Math.max( Math.abs(x - start_x), Math.abs(y - start_y) );
|
|
|
|
shape.setAttributeNS(null, "width", size);
|
|
|
|
shape.setAttributeNS(null, "height", size);
|
|
|
|
if(start_x < x) {
|
|
|
|
shape.setAttributeNS(null, "x", start_x);
|
|
|
|
} else {
|
|
|
|
shape.setAttributeNS(null, "x", start_x - size);
|
|
|
|
}
|
|
|
|
if(start_y < y) {
|
|
|
|
shape.setAttributeNS(null, "y", start_y);
|
|
|
|
} else {
|
|
|
|
shape.setAttributeNS(null, "y", start_y - size);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "select":
|
|
|
|
case "rect":
|
|
|
|
if (start_x < x) {
|
|
|
|
shape.setAttributeNS(null, "x", start_x);
|
|
|
|
shape.setAttributeNS(null, "width", x - start_x);
|
|
|
|
} else {
|
|
|
|
shape.setAttributeNS(null, "x", x);
|
|
|
|
shape.setAttributeNS(null, "width", start_x - x);
|
|
|
|
}
|
|
|
|
if (start_y < y) {
|
|
|
|
shape.setAttributeNS(null, "y", start_y);
|
|
|
|
shape.setAttributeNS(null, "height", y - start_y);
|
|
|
|
} else {
|
|
|
|
shape.setAttributeNS(null, "y", y);
|
|
|
|
shape.setAttributeNS(null, "height", start_y - y);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "circle":
|
|
|
|
var cx = shape.getAttributeNS(null, "cx");
|
|
|
|
var cy = shape.getAttributeNS(null, "cy");
|
|
|
|
var rad = Math.sqrt( (x-cx)*(x-cx) + (y-cy)*(y-cy) );
|
2009-06-03 15:00:48 +00:00
|
|
|
shape.setAttributeNS(null, "r", rad);
|
2009-06-02 16:40:33 +00:00
|
|
|
break;
|
|
|
|
case "ellipse":
|
|
|
|
var cx = shape.getAttributeNS(null, "cx");
|
|
|
|
var cy = shape.getAttributeNS(null, "cy");
|
|
|
|
shape.setAttributeNS(null, "rx", Math.abs(x - cx) );
|
|
|
|
shape.setAttributeNS(null, "ry", Math.abs(y - cy) );
|
|
|
|
break;
|
|
|
|
case "fhellipse":
|
|
|
|
case "fhrect":
|
|
|
|
freehand_min_x = Math.min(x, freehand_min_x);
|
|
|
|
freehand_max_x = Math.max(x, freehand_max_x);
|
|
|
|
freehand_min_y = Math.min(y, freehand_min_y);
|
|
|
|
freehand_max_y = Math.max(y, freehand_max_y);
|
2009-06-03 08:41:25 +00:00
|
|
|
// break; missing on purpose
|
2009-06-02 16:40:33 +00:00
|
|
|
case "path":
|
|
|
|
d_attr += "L" + x + " " + y + " ";
|
2009-06-05 12:33:02 +00:00
|
|
|
var shape = svgdoc.getElementById(getId());
|
2009-06-02 16:40:33 +00:00
|
|
|
shape.setAttributeNS(null, "d", d_attr);
|
|
|
|
break;
|
2009-06-01 21:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mouseUp = function(evt)
|
|
|
|
{
|
2009-06-02 16:40:33 +00:00
|
|
|
if (!started) return;
|
|
|
|
|
|
|
|
started = false;
|
2009-06-05 12:33:02 +00:00
|
|
|
var element = svgdoc.getElementById(getId());
|
|
|
|
|
2009-06-02 16:40:33 +00:00
|
|
|
switch (current_mode)
|
2009-06-01 21:24:30 +00:00
|
|
|
{
|
2009-06-02 16:40:33 +00:00
|
|
|
case "select":
|
2009-06-03 08:51:50 +00:00
|
|
|
if (element.getAttribute('width') == 0 &&
|
|
|
|
element.getAttribute('height') == 0) {
|
2009-06-03 08:41:25 +00:00
|
|
|
// only one element is selected and stored in selected variable (or null)
|
|
|
|
} else {
|
2009-06-03 08:51:50 +00:00
|
|
|
// element.getAttribute('x')
|
|
|
|
// element.getAttribute('y')
|
2009-06-03 08:41:25 +00:00
|
|
|
// should scan elements which are in rect(x,y,width,height) and select them
|
|
|
|
}
|
2009-06-02 16:40:33 +00:00
|
|
|
element.parentNode.removeChild(element);
|
|
|
|
element = null;
|
|
|
|
break;
|
|
|
|
case "path":
|
|
|
|
d_attr = null;
|
|
|
|
element.setAttribute("opacity", current_opacity);
|
|
|
|
obj_num++;
|
|
|
|
break;
|
|
|
|
case "line":
|
2009-06-03 08:51:50 +00:00
|
|
|
if (element.getAttribute('x1') == element.getAttribute('x2') &&
|
|
|
|
element.getAttribute('y1') == element.getAttribute('y2')) {
|
2009-06-03 08:41:25 +00:00
|
|
|
element.parentNode.removeChild(element);
|
|
|
|
element = null;
|
|
|
|
} else {
|
|
|
|
element.setAttribute("opacity", current_opacity);
|
|
|
|
obj_num++;
|
|
|
|
}
|
2009-06-02 16:40:33 +00:00
|
|
|
break;
|
|
|
|
case "square":
|
|
|
|
case "rect":
|
2009-06-03 08:51:50 +00:00
|
|
|
if (element.getAttribute('width') == 0 &&
|
|
|
|
element.getAttribute('height') == 0) {
|
2009-06-03 08:41:25 +00:00
|
|
|
element.parentNode.removeChild(element);
|
|
|
|
element = null;
|
|
|
|
} else {
|
|
|
|
element.setAttribute("opacity", current_opacity);
|
|
|
|
obj_num++;
|
|
|
|
}
|
2009-06-02 16:40:33 +00:00
|
|
|
break;
|
|
|
|
case "circle":
|
2009-06-03 15:00:48 +00:00
|
|
|
if (element.getAttribute('r') == 0) {
|
|
|
|
element.parentNode.removeChild(element);
|
|
|
|
element = null;
|
|
|
|
} else {
|
|
|
|
element.setAttribute("opacity", current_opacity);
|
|
|
|
obj_num++;
|
|
|
|
}
|
|
|
|
break;
|
2009-06-02 16:40:33 +00:00
|
|
|
case "ellipse":
|
2009-06-03 08:51:50 +00:00
|
|
|
if (element.getAttribute('rx') == 0 &&
|
|
|
|
element.getAttribute('ry') == 0) {
|
2009-06-03 08:41:25 +00:00
|
|
|
element.parentNode.removeChild(element);
|
|
|
|
element = null;
|
|
|
|
} else {
|
|
|
|
element.setAttribute("opacity", current_opacity);
|
|
|
|
obj_num++;
|
|
|
|
}
|
2009-06-02 16:40:33 +00:00
|
|
|
break;
|
|
|
|
case "fhellipse":
|
|
|
|
d_attr = null;
|
|
|
|
element.parentNode.removeChild(element);
|
2009-06-03 08:41:25 +00:00
|
|
|
if ((freehand_max_x - freehand_min_x) > 0 &&
|
|
|
|
(freehand_max_y - freehand_min_y) > 0) {
|
|
|
|
addSvgElementFromJson({
|
|
|
|
"element": "ellipse",
|
|
|
|
"attr": {
|
|
|
|
"cx": (freehand_min_x + freehand_max_x) / 2,
|
|
|
|
"cy": (freehand_min_y + freehand_max_y) / 2,
|
|
|
|
"rx": (freehand_max_x - freehand_min_x) / 2,
|
|
|
|
"ry": (freehand_max_y - freehand_min_y) / 2,
|
2009-06-05 12:33:02 +00:00
|
|
|
"id": getId(),
|
2009-06-03 08:41:25 +00:00
|
|
|
"fill": current_fill,
|
|
|
|
"stroke": current_stroke,
|
|
|
|
"stroke-width": current_stroke_width,
|
|
|
|
"stroke-dasharray": current_stroke_style,
|
2009-06-04 13:43:58 +00:00
|
|
|
"opacity": current_opacity,
|
|
|
|
"stroke-opacity": current_stroke_opacity,
|
|
|
|
"fill-opacity": current_fill_opacity
|
2009-06-03 08:41:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
obj_num++;
|
|
|
|
}
|
2009-06-02 16:40:33 +00:00
|
|
|
break;
|
|
|
|
case "fhrect":
|
|
|
|
d_attr = null;
|
|
|
|
element.parentNode.removeChild(element);
|
2009-06-03 08:41:25 +00:00
|
|
|
if ((freehand_max_x - freehand_min_x) > 0 &&
|
|
|
|
(freehand_max_y - freehand_min_y) > 0) {
|
|
|
|
addSvgElementFromJson({
|
|
|
|
"element": "rect",
|
|
|
|
"attr": {
|
|
|
|
"x": freehand_min_x,
|
|
|
|
"y": freehand_min_y,
|
|
|
|
"width": (freehand_max_x - freehand_min_x),
|
|
|
|
"height": (freehand_max_y - freehand_min_y),
|
2009-06-05 12:33:02 +00:00
|
|
|
"id": getId(),
|
2009-06-03 08:41:25 +00:00
|
|
|
"fill": current_fill,
|
|
|
|
"stroke": current_stroke,
|
|
|
|
"stroke-width": current_stroke_width,
|
|
|
|
"stroke-dasharray": current_stroke_style,
|
2009-06-04 13:43:58 +00:00
|
|
|
"opacity": current_opacity,
|
|
|
|
"stroke-opacity": current_stroke_opacity,
|
|
|
|
"fill-opacity": current_fill_opacity
|
2009-06-03 08:41:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
obj_num++;
|
|
|
|
}
|
2009-06-02 16:40:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (element != null) {
|
|
|
|
cleanupElement(element);
|
2009-06-01 21:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// public functions
|
|
|
|
|
|
|
|
this.serialize = function(handler) {
|
|
|
|
var str = "<?xml version=\"1.0\" standalone=\"no\"?>\n"
|
|
|
|
str += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
|
|
|
str += svgToString(svgroot, 0);
|
|
|
|
handler(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.clear = function() {
|
|
|
|
var nodes = svgroot.childNodes;
|
|
|
|
var len = svgroot.childNodes.length;
|
|
|
|
var i = 0;
|
|
|
|
for(var rep = 0; rep < len; rep++){
|
2009-06-02 16:40:33 +00:00
|
|
|
if (nodes[i].nodeType == 1) { // element node
|
2009-06-01 21:24:30 +00:00
|
|
|
nodes[i].parentNode.removeChild(nodes[i]);
|
|
|
|
} else {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-06 12:25:26 +00:00
|
|
|
this.getMode = function() {
|
|
|
|
return current_mode;
|
|
|
|
}
|
|
|
|
|
2009-06-01 21:24:30 +00:00
|
|
|
this.setMode = function(name) {
|
2009-06-02 16:40:33 +00:00
|
|
|
current_mode = name;
|
2009-06-01 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 12:25:26 +00:00
|
|
|
this.getStrokeColor = function() {
|
|
|
|
return current_stroke;
|
|
|
|
}
|
|
|
|
|
2009-06-01 21:24:30 +00:00
|
|
|
this.setStrokeColor = function(color) {
|
2009-06-02 16:40:33 +00:00
|
|
|
current_stroke = color;
|
2009-06-01 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 12:25:26 +00:00
|
|
|
this.getFillColor = function() {
|
|
|
|
return current_fill;
|
|
|
|
}
|
|
|
|
|
2009-06-01 21:24:30 +00:00
|
|
|
this.setFillColor = function(color) {
|
2009-06-02 16:40:33 +00:00
|
|
|
current_fill = color;
|
2009-06-01 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 12:25:26 +00:00
|
|
|
this.getStrokeWidth = function() {
|
|
|
|
return current_stroke_width;
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:01:07 +00:00
|
|
|
this.setStrokeWidth = function(val) {
|
2009-06-02 16:40:33 +00:00
|
|
|
current_stroke_width = val;
|
2009-06-01 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 12:25:26 +00:00
|
|
|
this.getStrokeStyle = function() {
|
|
|
|
return current_stroke_style;
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:01:07 +00:00
|
|
|
this.setStrokeStyle = function(val) {
|
2009-06-02 16:40:33 +00:00
|
|
|
current_stroke_style = val;
|
2009-06-01 22:01:07 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 12:25:26 +00:00
|
|
|
this.getOpacity = function() {
|
|
|
|
return current_opacity;
|
|
|
|
}
|
|
|
|
|
2009-06-04 13:43:58 +00:00
|
|
|
this.setOpacity = function(val) {
|
|
|
|
current_opacity = val;
|
|
|
|
}
|
|
|
|
|
2009-06-06 12:25:26 +00:00
|
|
|
this.getFillOpacity = function() {
|
|
|
|
return current_fill_opacity;
|
|
|
|
}
|
|
|
|
|
2009-06-04 13:43:58 +00:00
|
|
|
this.setFillOpacity = function(val) {
|
|
|
|
current_fill_opacity = val;
|
|
|
|
}
|
|
|
|
|
2009-06-06 12:25:26 +00:00
|
|
|
this.getStrokeOpacity = function() {
|
|
|
|
return current_stroke_opacity;
|
|
|
|
}
|
|
|
|
|
2009-06-04 13:43:58 +00:00
|
|
|
this.setStrokeOpacity = function(val) {
|
|
|
|
current_stroke_opacity = val;
|
|
|
|
}
|
|
|
|
|
2009-06-01 21:24:30 +00:00
|
|
|
this.setup = function(evt) {
|
|
|
|
assignAttributes(svgroot, {
|
2009-06-02 11:09:49 +00:00
|
|
|
"onmouseup": "svgcanvas.mouseUp(evt)",
|
|
|
|
"onmousedown": "svgcanvas.mouseDown(evt)",
|
|
|
|
"onmousemove": "svgcanvas.mouseMove(evt)"
|
2009-06-01 21:24:30 +00:00
|
|
|
});
|
|
|
|
}
|
2009-06-01 17:35:22 +00:00
|
|
|
|
|
|
|
}
|