| 2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.gfx.utils"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.gfx.utils"] = true;
|
|
|
3 |
dojo.provide("dojox.gfx.utils");
|
|
|
4 |
|
|
|
5 |
dojo.require("dojox.gfx");
|
|
|
6 |
|
|
|
7 |
dojox.gfx.utils.serialize = function(
|
|
|
8 |
/* dojox.gfx.Surface || dojox.gfx.Shape */ object
|
|
|
9 |
){
|
|
|
10 |
var t = {}, v, isSurface = object instanceof dojox.gfx.Surface;
|
|
|
11 |
if(isSurface || object instanceof dojox.gfx.Group){
|
|
|
12 |
t.children = [];
|
|
|
13 |
for(var i = 0; i < object.children.length; ++i){
|
|
|
14 |
t.children.push(dojox.gfx.utils.serialize(object.children[i]));
|
|
|
15 |
}
|
|
|
16 |
if(isSurface){
|
|
|
17 |
return t.children; // Array
|
|
|
18 |
}
|
|
|
19 |
}else{
|
|
|
20 |
t.shape = object.getShape();
|
|
|
21 |
}
|
|
|
22 |
if(object.getTransform){
|
|
|
23 |
v = object.getTransform();
|
|
|
24 |
if(v){ t.transform = v; }
|
|
|
25 |
}
|
|
|
26 |
if(object.getStroke){
|
|
|
27 |
v = object.getStroke();
|
|
|
28 |
if(v){ t.stroke = v; }
|
|
|
29 |
}
|
|
|
30 |
if(object.getFill){
|
|
|
31 |
v = object.getFill();
|
|
|
32 |
if(v){ t.fill = v; }
|
|
|
33 |
}
|
|
|
34 |
if(object.getFont){
|
|
|
35 |
v = object.getFont();
|
|
|
36 |
if(v){ t.font = v; }
|
|
|
37 |
}
|
|
|
38 |
return t; // Object
|
|
|
39 |
};
|
|
|
40 |
|
|
|
41 |
dojox.gfx.utils.toJson = function(
|
|
|
42 |
/* dojox.gfx.Surface || dojox.gfx.Shape */ object,
|
|
|
43 |
/* Boolean? */ prettyPrint
|
|
|
44 |
){
|
|
|
45 |
return dojo.toJson(dojox.gfx.utils.serialize(object), prettyPrint); // String
|
|
|
46 |
};
|
|
|
47 |
|
|
|
48 |
dojox.gfx.utils.deserialize = function(
|
|
|
49 |
/* dojox.gfx.Surface || dojox.gfx.Shape */ parent,
|
|
|
50 |
/* dojox.gfx.Shape || Array */ object
|
|
|
51 |
){
|
|
|
52 |
if(object instanceof Array){
|
|
|
53 |
var t = [];
|
|
|
54 |
for(var i = 0; i < object.length; ++i){
|
|
|
55 |
t.push(dojox.gfx.utils.deserialize(parent, object[i]));
|
|
|
56 |
}
|
|
|
57 |
return t; // Array
|
|
|
58 |
}
|
|
|
59 |
var shape = ("shape" in object) ? parent.createShape(object.shape) : parent.createGroup();
|
|
|
60 |
if("transform" in object){
|
|
|
61 |
shape.setTransform(object.transform);
|
|
|
62 |
}
|
|
|
63 |
if("stroke" in object){
|
|
|
64 |
shape.setStroke(object.stroke);
|
|
|
65 |
}
|
|
|
66 |
if("fill" in object){
|
|
|
67 |
shape.setFill(object.fill);
|
|
|
68 |
}
|
|
|
69 |
if("font" in object){
|
|
|
70 |
shape.setFont(object.font);
|
|
|
71 |
}
|
|
|
72 |
if("children" in object){
|
|
|
73 |
for(var i = 0; i < object.children.length; ++i){
|
|
|
74 |
dojox.gfx.utils.deserialize(shape, object.children[i]);
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
return shape; // dojox.gfx.Shape
|
|
|
78 |
};
|
|
|
79 |
|
|
|
80 |
dojox.gfx.utils.fromJson = function(
|
|
|
81 |
/* dojox.gfx.Surface || dojox.gfx.Shape */ parent,
|
|
|
82 |
/* String */ json
|
|
|
83 |
){
|
|
|
84 |
return dojox.gfx.utils.deserialize(parent, dojo.fromJson(json)); // Array || dojox.gfx.Shape
|
|
|
85 |
};
|
|
|
86 |
|
|
|
87 |
}
|