don't add elements when not needed (eg. size = 0 x 0)
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@18 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
320
svgcanvas.js
320
svgcanvas.js
@@ -29,6 +29,7 @@ function SvgCanvas(doc)
|
|||||||
var freehand_max_x = null;
|
var freehand_max_x = null;
|
||||||
var freehand_min_y = null;
|
var freehand_min_y = null;
|
||||||
var freehand_max_y = null;
|
var freehand_max_y = null;
|
||||||
|
var selected = null;
|
||||||
|
|
||||||
// private functions
|
// private functions
|
||||||
|
|
||||||
@@ -110,111 +111,112 @@ function SvgCanvas(doc)
|
|||||||
{
|
{
|
||||||
var x = evt.pageX;
|
var x = evt.pageX;
|
||||||
var y = evt.pageY;
|
var y = evt.pageY;
|
||||||
switch (current_mode)
|
switch (current_mode) {
|
||||||
{
|
case "select":
|
||||||
case "select":
|
started = true;
|
||||||
started = true;
|
start_x = x;
|
||||||
start_x = x;
|
start_y = y;
|
||||||
start_y = y;
|
if (evt.target != svgroot)
|
||||||
addSvgElementFromJson({
|
selected = evt.target;
|
||||||
"element": "rect",
|
addSvgElementFromJson({
|
||||||
"attr": {
|
"element": "rect",
|
||||||
"x": x,
|
"attr": {
|
||||||
"y": y,
|
"x": x,
|
||||||
"width": "1px",
|
"y": y,
|
||||||
"height": "1px",
|
"width": 0,
|
||||||
"id": "rect_" + obj_num,
|
"height": 0,
|
||||||
"fill": '#DBEBF9',
|
"id": "rect_" + obj_num,
|
||||||
"stroke": '#CEE2F7',
|
"fill": '#DBEBF9',
|
||||||
"stroke-width": 1,
|
"stroke": '#CEE2F7',
|
||||||
"fill-opacity": 0.5
|
"stroke-width": 1,
|
||||||
}
|
"fill-opacity": 0.5
|
||||||
});
|
}
|
||||||
break;
|
});
|
||||||
case "fhellipse":
|
break;
|
||||||
case "fhrect":
|
case "fhellipse":
|
||||||
case "path":
|
case "fhrect":
|
||||||
started = true;
|
case "path":
|
||||||
d_attr = "M" + x + " " + y + " ";
|
started = true;
|
||||||
addSvgElementFromJson({
|
d_attr = "M" + x + " " + y + " ";
|
||||||
"element": "path",
|
addSvgElementFromJson({
|
||||||
"attr": {
|
"element": "path",
|
||||||
"d": d_attr,
|
"attr": {
|
||||||
"id": "path_" + obj_num,
|
"d": d_attr,
|
||||||
"fill": "none",
|
"id": "path_" + obj_num,
|
||||||
"stroke": current_stroke,
|
"fill": "none",
|
||||||
"stroke-width": current_stroke_width,
|
"stroke": current_stroke,
|
||||||
"stroke-dasharray": current_stroke_style,
|
"stroke-width": current_stroke_width,
|
||||||
"opacity": 0.5
|
"stroke-dasharray": current_stroke_style,
|
||||||
}
|
"opacity": 0.5
|
||||||
});
|
}
|
||||||
freehand_min_x = x;
|
});
|
||||||
freehand_max_x = x;
|
freehand_min_x = x;
|
||||||
freehand_min_y = y;
|
freehand_max_x = x;
|
||||||
freehand_max_y = y;
|
freehand_min_y = y;
|
||||||
break;
|
freehand_max_y = y;
|
||||||
case "square":
|
break;
|
||||||
case "rect":
|
case "square":
|
||||||
started = true;
|
case "rect":
|
||||||
start_x = x;
|
started = true;
|
||||||
start_y = y;
|
start_x = x;
|
||||||
addSvgElementFromJson({
|
start_y = y;
|
||||||
"element": "rect",
|
addSvgElementFromJson({
|
||||||
"attr": {
|
"element": "rect",
|
||||||
"x": x,
|
"attr": {
|
||||||
"y": y,
|
"x": x,
|
||||||
"width": "1px",
|
"y": y,
|
||||||
"height": "1px",
|
"width": 0,
|
||||||
"id": "rect_" + obj_num,
|
"height": 0,
|
||||||
"fill": current_fill,
|
"id": "rect_" + obj_num,
|
||||||
"stroke": current_stroke,
|
"fill": current_fill,
|
||||||
"stroke-width": current_stroke_width,
|
"stroke": current_stroke,
|
||||||
"stroke-dasharray": current_stroke_style,
|
"stroke-width": current_stroke_width,
|
||||||
"opacity": 0.5
|
"stroke-dasharray": current_stroke_style,
|
||||||
}
|
"opacity": 0.5
|
||||||
});
|
}
|
||||||
break;
|
});
|
||||||
case "line":
|
break;
|
||||||
started = true;
|
case "line":
|
||||||
addSvgElementFromJson({
|
started = true;
|
||||||
"element": "line",
|
addSvgElementFromJson({
|
||||||
"attr": {
|
"element": "line",
|
||||||
"x1": x,
|
"attr": {
|
||||||
"y1": y,
|
"x1": x,
|
||||||
"x2": x + 1 + "px",
|
"y1": y,
|
||||||
"y2": y + 1 + "px",
|
"x2": x,
|
||||||
"id": "line_" + obj_num,
|
"y2": y,
|
||||||
"stroke": current_stroke,
|
"id": "line_" + obj_num,
|
||||||
"stroke-width": current_stroke_width,
|
"stroke": current_stroke,
|
||||||
"stroke-dasharray": current_stroke_style,
|
"stroke-width": current_stroke_width,
|
||||||
"opacity": 0.5
|
"stroke-dasharray": current_stroke_style,
|
||||||
}
|
"opacity": 0.5
|
||||||
});
|
}
|
||||||
break;
|
});
|
||||||
case "circle":
|
break;
|
||||||
case "ellipse":
|
case "circle":
|
||||||
started = true;
|
case "ellipse":
|
||||||
addSvgElementFromJson({
|
started = true;
|
||||||
"element": "ellipse",
|
addSvgElementFromJson({
|
||||||
"attr": {
|
"element": "ellipse",
|
||||||
"cx": x,
|
"attr": {
|
||||||
"cy": y,
|
"cx": x,
|
||||||
"rx": 1 + "px",
|
"cy": y,
|
||||||
"ry": 1 + "px",
|
"rx": 0,
|
||||||
"id": "ellipse_" + obj_num,
|
"ry": 0,
|
||||||
"fill": current_fill,
|
"id": "ellipse_" + obj_num,
|
||||||
"stroke": current_stroke,
|
"fill": current_fill,
|
||||||
"stroke-width": current_stroke_width,
|
"stroke": current_stroke,
|
||||||
"stroke-dasharray": current_stroke_style,
|
"stroke-width": current_stroke_width,
|
||||||
"opacity": 0.5
|
"stroke-dasharray": current_stroke_style,
|
||||||
}
|
"opacity": 0.5
|
||||||
});
|
}
|
||||||
break;
|
});
|
||||||
case "delete":
|
|
||||||
var t = evt.target;
|
|
||||||
if (t == svgroot) return;
|
|
||||||
t.parentNode.removeChild(t);
|
|
||||||
break;
|
break;
|
||||||
|
case "delete":
|
||||||
|
var t = evt.target;
|
||||||
|
if (t == svgroot) return;
|
||||||
|
t.parentNode.removeChild(t);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +288,7 @@ function SvgCanvas(doc)
|
|||||||
freehand_max_x = Math.max(x, freehand_max_x);
|
freehand_max_x = Math.max(x, freehand_max_x);
|
||||||
freehand_min_y = Math.min(y, freehand_min_y);
|
freehand_min_y = Math.min(y, freehand_min_y);
|
||||||
freehand_max_y = Math.max(y, freehand_max_y);
|
freehand_max_y = Math.max(y, freehand_max_y);
|
||||||
// break missing on purpose
|
// break; missing on purpose
|
||||||
case "path":
|
case "path":
|
||||||
d_attr += "L" + x + " " + y + " ";
|
d_attr += "L" + x + " " + y + " ";
|
||||||
var shape = svgdoc.getElementById("path_" + obj_num);
|
var shape = svgdoc.getElementById("path_" + obj_num);
|
||||||
@@ -305,6 +307,14 @@ function SvgCanvas(doc)
|
|||||||
{
|
{
|
||||||
case "select":
|
case "select":
|
||||||
element = svgdoc.getElementById("rect_" + obj_num);
|
element = svgdoc.getElementById("rect_" + obj_num);
|
||||||
|
if (element.getFloatTrait('width') == 0 &&
|
||||||
|
if (element.getFloatTrait('height') == 0) {
|
||||||
|
// only one element is selected and stored in selected variable (or null)
|
||||||
|
} else {
|
||||||
|
// element.getFloatTrait('x')
|
||||||
|
// element.getFloatTrait('y')
|
||||||
|
// should scan elements which are in rect(x,y,width,height) and select them
|
||||||
|
}
|
||||||
element.parentNode.removeChild(element);
|
element.parentNode.removeChild(element);
|
||||||
element = null;
|
element = null;
|
||||||
break;
|
break;
|
||||||
@@ -316,62 +326,86 @@ function SvgCanvas(doc)
|
|||||||
break;
|
break;
|
||||||
case "line":
|
case "line":
|
||||||
element = svgdoc.getElementById("line_" + obj_num);
|
element = svgdoc.getElementById("line_" + obj_num);
|
||||||
element.setAttribute("opacity", current_opacity);
|
if (element.getFloatTrait('x1') == element.getFloatTrait('x2') &&
|
||||||
obj_num++;
|
element.getFloatTrait('y1') == element.getFloatTrait('y2')) {
|
||||||
|
element.parentNode.removeChild(element);
|
||||||
|
element = null;
|
||||||
|
} else {
|
||||||
|
element.setAttribute("opacity", current_opacity);
|
||||||
|
obj_num++;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "square":
|
case "square":
|
||||||
case "rect":
|
case "rect":
|
||||||
element = svgdoc.getElementById("rect_" + obj_num);
|
element = svgdoc.getElementById("rect_" + obj_num);
|
||||||
element.setAttribute("opacity", current_opacity);
|
if (element.getFloatTrait('width') == 0 &&
|
||||||
obj_num++;
|
element.getFloatTrait('height') == 0) {
|
||||||
|
element.parentNode.removeChild(element);
|
||||||
|
element = null;
|
||||||
|
} else {
|
||||||
|
element.setAttribute("opacity", current_opacity);
|
||||||
|
obj_num++;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "circle":
|
case "circle":
|
||||||
case "ellipse":
|
case "ellipse":
|
||||||
element = svgdoc.getElementById("ellipse_" + obj_num);
|
element = svgdoc.getElementById("ellipse_" + obj_num);
|
||||||
element.setAttribute("opacity", current_opacity);
|
if (element.getFloatTrait('rx') == 0 &&
|
||||||
obj_num++;
|
element.getFloatTrait('ry') == 0) {
|
||||||
|
element.parentNode.removeChild(element);
|
||||||
|
element = null;
|
||||||
|
} else {
|
||||||
|
element.setAttribute("opacity", current_opacity);
|
||||||
|
obj_num++;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "fhellipse":
|
case "fhellipse":
|
||||||
d_attr = null;
|
d_attr = null;
|
||||||
element = svgdoc.getElementById("path_" + obj_num);
|
element = svgdoc.getElementById("path_" + obj_num);
|
||||||
element.parentNode.removeChild(element);
|
element.parentNode.removeChild(element);
|
||||||
addSvgElementFromJson({
|
if ((freehand_max_x - freehand_min_x) > 0 &&
|
||||||
"element": "ellipse",
|
(freehand_max_y - freehand_min_y) > 0) {
|
||||||
"attr": {
|
addSvgElementFromJson({
|
||||||
"cx": (freehand_min_x + freehand_max_x) / 2,
|
"element": "ellipse",
|
||||||
"cy": (freehand_min_y + freehand_max_y) / 2,
|
"attr": {
|
||||||
"rx": (freehand_max_x - freehand_min_x) / 2 + "px",
|
"cx": (freehand_min_x + freehand_max_x) / 2,
|
||||||
"ry": (freehand_max_y - freehand_min_y) / 2 + "px",
|
"cy": (freehand_min_y + freehand_max_y) / 2,
|
||||||
"id": "ellipse_" + obj_num,
|
"rx": (freehand_max_x - freehand_min_x) / 2,
|
||||||
"fill": current_fill,
|
"ry": (freehand_max_y - freehand_min_y) / 2,
|
||||||
"stroke": current_stroke,
|
"id": "ellipse_" + obj_num,
|
||||||
"stroke-width": current_stroke_width,
|
"fill": current_fill,
|
||||||
"stroke-dasharray": current_stroke_style,
|
"stroke": current_stroke,
|
||||||
"opacity": current_opacity
|
"stroke-width": current_stroke_width,
|
||||||
}
|
"stroke-dasharray": current_stroke_style,
|
||||||
});
|
"opacity": current_opacity
|
||||||
obj_num++;
|
}
|
||||||
|
});
|
||||||
|
obj_num++;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "fhrect":
|
case "fhrect":
|
||||||
d_attr = null;
|
d_attr = null;
|
||||||
element = svgdoc.getElementById("path_" + obj_num);
|
element = svgdoc.getElementById("path_" + obj_num);
|
||||||
element.parentNode.removeChild(element);
|
element.parentNode.removeChild(element);
|
||||||
addSvgElementFromJson({
|
if ((freehand_max_x - freehand_min_x) > 0 &&
|
||||||
"element": "rect",
|
(freehand_max_y - freehand_min_y) > 0) {
|
||||||
"attr": {
|
addSvgElementFromJson({
|
||||||
"x": freehand_min_x,
|
"element": "rect",
|
||||||
"y": freehand_min_y,
|
"attr": {
|
||||||
"width": (freehand_max_x - freehand_min_x) + "px",
|
"x": freehand_min_x,
|
||||||
"height": (freehand_max_y - freehand_min_y) + "px",
|
"y": freehand_min_y,
|
||||||
"id": "rect_" + obj_num,
|
"width": (freehand_max_x - freehand_min_x),
|
||||||
"fill": current_fill,
|
"height": (freehand_max_y - freehand_min_y),
|
||||||
"stroke": current_stroke,
|
"id": "rect_" + obj_num,
|
||||||
"stroke-width": current_stroke_width,
|
"fill": current_fill,
|
||||||
"stroke-dasharray": current_stroke_style,
|
"stroke": current_stroke,
|
||||||
"opacity": current_opacity
|
"stroke-width": current_stroke_width,
|
||||||
}
|
"stroke-dasharray": current_stroke_style,
|
||||||
});
|
"opacity": current_opacity
|
||||||
obj_num++;
|
}
|
||||||
|
});
|
||||||
|
obj_num++;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user