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");
5 dojo.require("dojox.gfx");
7 dojox.gfx.utils.serialize = function(
8 /* dojox.gfx.Surface || dojox.gfx.Shape */ object
10 var t = {}, v, isSurface = object instanceof dojox.gfx.Surface;
11 if(isSurface || object instanceof dojox.gfx.Group){
13 for(var i = 0; i < object.children.length; ++i){
14 t.children.push(dojox.gfx.utils.serialize(object.children[i]));
17 return t.children; // Array
20 t.shape = object.getShape();
22 if(object.getTransform){
23 v = object.getTransform();
24 if(v){ t.transform = v; }
27 v = object.getStroke();
28 if(v){ t.stroke = v; }
41 dojox.gfx.utils.toJson = function(
42 /* dojox.gfx.Surface || dojox.gfx.Shape */ object,
43 /* Boolean? */ prettyPrint
45 return dojo.toJson(dojox.gfx.utils.serialize(object), prettyPrint); // String
48 dojox.gfx.utils.deserialize = function(
49 /* dojox.gfx.Surface || dojox.gfx.Shape */ parent,
50 /* dojox.gfx.Shape || Array */ object
52 if(object instanceof Array){
54 for(var i = 0; i < object.length; ++i){
55 t.push(dojox.gfx.utils.deserialize(parent, object[i]));
59 var shape = ("shape" in object) ? parent.createShape(object.shape) : parent.createGroup();
60 if("transform" in object){
61 shape.setTransform(object.transform);
63 if("stroke" in object){
64 shape.setStroke(object.stroke);
67 shape.setFill(object.fill);
70 shape.setFont(object.font);
72 if("children" in object){
73 for(var i = 0; i < object.children.length; ++i){
74 dojox.gfx.utils.deserialize(shape, object.children[i]);
77 return shape; // dojox.gfx.Shape
80 dojox.gfx.utils.fromJson = function(
81 /* dojox.gfx.Surface || dojox.gfx.Shape */ parent,
84 return dojox.gfx.utils.deserialize(parent, dojo.fromJson(json)); // Array || dojox.gfx.Shape