Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.gfx.vml");
14
dojo.require("dojo.dom");
15
dojo.require("dojo.math");
16
dojo.require("dojo.lang.declare");
17
dojo.require("dojo.lang.extras");
18
dojo.require("dojo.string.*");
19
dojo.require("dojo.html.metrics");
20
dojo.require("dojo.gfx.color");
21
dojo.require("dojo.gfx.common");
22
dojo.require("dojo.gfx.shape");
23
dojo.require("dojo.gfx.path");
24
dojo.require("dojo.experimental");
25
dojo.experimental("dojo.gfx.vml");
26
dojo.gfx.vml.xmlns = "urn:schemas-microsoft-com:vml";
27
dojo.gfx.vml._parseFloat = function (str) {
28
	return str.match(/^\d+f$/i) ? parseInt(str) / 65536 : parseFloat(str);
29
};
30
dojo.gfx.vml.cm_in_pt = 72 / 2.54;
31
dojo.gfx.vml.mm_in_pt = 7.2 / 2.54;
32
dojo.gfx.vml.px_in_pt = function () {
33
	return dojo.html.getCachedFontMeasurements()["12pt"] / 12;
34
};
35
dojo.gfx.vml.pt2px = function (len) {
36
	return len * this.px_in_pt();
37
};
38
dojo.gfx.vml.px2pt = function (len) {
39
	return len / this.px_in_pt();
40
};
41
dojo.gfx.vml.normalizedLength = function (len) {
42
	if (len.length == 0) {
43
		return 0;
44
	}
45
	if (len.length > 2) {
46
		var px_in_pt = this.px_in_pt();
47
		var val = parseFloat(len);
48
		switch (len.slice(-2)) {
49
		  case "px":
50
			return val;
51
		  case "pt":
52
			return val * px_in_pt;
53
		  case "in":
54
			return val * 72 * px_in_pt;
55
		  case "pc":
56
			return val * 12 * px_in_pt;
57
		  case "mm":
58
			return val / this.mm_in_pt * px_in_pt;
59
		  case "cm":
60
			return val / this.cm_in_pt * px_in_pt;
61
		}
62
	}
63
	return parseFloat(len);
64
};
65
dojo.lang.extend(dojo.gfx.Shape, {setFill:function (fill) {
66
	if (!fill) {
67
		this.fillStyle = null;
68
		this.rawNode.filled = false;
69
		return this;
70
	}
71
	if (typeof (fill) == "object" && "type" in fill) {
72
		switch (fill.type) {
73
		  case "linear":
74
			var f = dojo.gfx.makeParameters(dojo.gfx.defaultLinearGradient, fill);
75
			this.fillStyle = f;
76
			var s = "";
77
			for (var i = 0; i < f.colors.length; ++i) {
78
				f.colors[i].color = dojo.gfx.normalizeColor(f.colors[i].color);
79
				s += f.colors[i].offset.toFixed(8) + " " + f.colors[i].color.toHex() + ";";
80
			}
81
			var fo = this.rawNode.fill;
82
			fo.colors.value = s;
83
			fo.method = "sigma";
84
			fo.type = "gradient";
85
			fo.angle = (dojo.math.radToDeg(Math.atan2(f.x2 - f.x1, f.y2 - f.y1)) + 180) % 360;
86
			fo.on = true;
87
			break;
88
		  case "radial":
89
			var f = dojo.gfx.makeParameters(dojo.gfx.defaultRadialGradient, fill);
90
			this.fillStyle = f;
91
			var w = parseFloat(this.rawNode.style.width);
92
			var h = parseFloat(this.rawNode.style.height);
93
			var c = isNaN(w) ? 1 : 2 * f.r / w;
94
			var i = f.colors.length - 1;
95
			f.colors[i].color = dojo.gfx.normalizeColor(f.colors[i].color);
96
			var s = "0 " + f.colors[i].color.toHex();
97
			for (; i >= 0; --i) {
98
				f.colors[i].color = dojo.gfx.normalizeColor(f.colors[i].color);
99
				s += (1 - c * f.colors[i].offset).toFixed(8) + " " + f.colors[i].color.toHex() + ";";
100
			}
101
			var fo = this.rawNode.fill;
102
			fo.colors.value = s;
103
			fo.method = "sigma";
104
			fo.type = "gradientradial";
105
			if (isNaN(w) || isNaN(h)) {
106
				fo.focusposition = "0.5 0.5";
107
			} else {
108
				fo.focusposition = (f.cx / w).toFixed(8) + " " + (f.cy / h).toFixed(8);
109
			}
110
			fo.focussize = "0 0";
111
			fo.on = true;
112
			break;
113
		  case "pattern":
114
			var f = dojo.gfx.makeParameters(dojo.gfx.defaultPattern, fill);
115
			this.fillStyle = f;
116
			var fo = this.rawNode.fill;
117
			fo.type = "tile";
118
			fo.src = f.src;
119
			if (f.width && f.height) {
120
				fo.size.x = dojo.gfx.vml.px2pt(f.width);
121
				fo.size.y = dojo.gfx.vml.px2pt(f.height);
122
			}
123
			fo.alignShape = false;
124
			fo.position.x = 0;
125
			fo.position.y = 0;
126
			fo.origin.x = f.width ? f.x / f.width : 0;
127
			fo.origin.y = f.height ? f.y / f.height : 0;
128
			fo.on = true;
129
			break;
130
		}
131
		this.rawNode.fill.opacity = 1;
132
		return this;
133
	}
134
	this.fillStyle = dojo.gfx.normalizeColor(fill);
135
	this.rawNode.fillcolor = this.fillStyle.toHex();
136
	this.rawNode.fill.opacity = this.fillStyle.a;
137
	this.rawNode.filled = true;
138
	return this;
139
}, setStroke:function (stroke) {
140
	if (!stroke) {
141
		this.strokeStyle = null;
142
		this.rawNode.stroked = false;
143
		return this;
144
	}
145
	this.strokeStyle = dojo.gfx.makeParameters(dojo.gfx.defaultStroke, stroke);
146
	this.strokeStyle.color = dojo.gfx.normalizeColor(this.strokeStyle.color);
147
	var s = this.strokeStyle;
148
	this.rawNode.stroked = true;
149
	this.rawNode.strokecolor = s.color.toCss();
150
	this.rawNode.strokeweight = s.width + "px";
151
	if (this.rawNode.stroke) {
152
		this.rawNode.stroke.opacity = s.color.a;
153
		this.rawNode.stroke.endcap = this._translate(this._capMap, s.cap);
154
		if (typeof (s.join) == "number") {
155
			this.rawNode.stroke.joinstyle = "miter";
156
			this.rawNode.stroke.miterlimit = s.join;
157
		} else {
158
			this.rawNode.stroke.joinstyle = s.join;
159
		}
160
	}
161
	return this;
162
}, _capMap:{butt:"flat"}, _capMapReversed:{flat:"butt"}, _translate:function (dict, value) {
163
	return (value in dict) ? dict[value] : value;
164
}, _applyTransform:function () {
165
	var matrix = this._getRealMatrix();
166
	if (!matrix) {
167
		return this;
168
	}
169
	var skew = this.rawNode.skew;
170
	if (typeof (skew) == "undefined") {
171
		for (var i = 0; i < this.rawNode.childNodes.length; ++i) {
172
			if (this.rawNode.childNodes[i].tagName == "skew") {
173
				skew = this.rawNode.childNodes[i];
174
				break;
175
			}
176
		}
177
	}
178
	if (skew) {
179
		skew.on = false;
180
		var mt = matrix.xx.toFixed(8) + " " + matrix.xy.toFixed(8) + " " + matrix.yx.toFixed(8) + " " + matrix.yy.toFixed(8) + " 0 0";
181
		var offset = Math.floor(matrix.dx).toFixed() + "px " + Math.floor(matrix.dy).toFixed() + "px";
182
		var l = parseFloat(this.rawNode.style.left);
183
		var t = parseFloat(this.rawNode.style.top);
184
		var w = parseFloat(this.rawNode.style.width);
185
		var h = parseFloat(this.rawNode.style.height);
186
		if (isNaN(l)) {
187
			l = 0;
188
		}
189
		if (isNaN(t)) {
190
			t = 0;
191
		}
192
		if (isNaN(w)) {
193
			w = 1;
194
		}
195
		if (isNaN(h)) {
196
			h = 1;
197
		}
198
		var origin = (-l / w - 0.5).toFixed(8) + " " + (-t / h - 0.5).toFixed(8);
199
		skew.matrix = mt;
200
		skew.origin = origin;
201
		skew.offset = offset;
202
		skew.on = true;
203
	}
204
	return this;
205
}, setRawNode:function (rawNode) {
206
	rawNode.stroked = false;
207
	rawNode.filled = false;
208
	this.rawNode = rawNode;
209
}, attachFill:function (rawNode) {
210
	var fillStyle = null;
211
	var fo = rawNode.fill;
212
	if (rawNode) {
213
		if (fo.on && fo.type == "gradient") {
214
			var fillStyle = dojo.lang.shallowCopy(dojo.gfx.defaultLinearGradient, true);
215
			var rad = dojo.math.degToRad(fo.angle);
216
			fillStyle.x2 = Math.cos(rad);
217
			fillStyle.y2 = Math.sin(rad);
218
			fillStyle.colors = [];
219
			var stops = fo.colors.value.split(";");
220
			for (var i = 0; i < stops.length; ++i) {
221
				var t = stops[i].match(/\S+/g);
222
				if (!t || t.length != 2) {
223
					continue;
224
				}
225
				fillStyle.colors.push({offset:dojo.gfx.vml._parseFloat(t[0]), color:new dojo.gfx.color.Color(t[1])});
226
			}
227
		} else {
228
			if (fo.on && fo.type == "gradientradial") {
229
				var fillStyle = dojo.lang.shallowCopy(dojo.gfx.defaultRadialGradient, true);
230
				var w = parseFloat(rawNode.style.width);
231
				var h = parseFloat(rawNode.style.height);
232
				fillStyle.cx = isNaN(w) ? 0 : fo.focusposition.x * w;
233
				fillStyle.cy = isNaN(h) ? 0 : fo.focusposition.y * h;
234
				fillStyle.r = isNaN(w) ? 1 : w / 2;
235
				fillStyle.colors = [];
236
				var stops = fo.colors.value.split(";");
237
				for (var i = stops.length - 1; i >= 0; --i) {
238
					var t = stops[i].match(/\S+/g);
239
					if (!t || t.length != 2) {
240
						continue;
241
					}
242
					fillStyle.colors.push({offset:dojo.gfx.vml._parseFloat(t[0]), color:new dojo.gfx.color.Color(t[1])});
243
				}
244
			} else {
245
				if (fo.on && fo.type == "tile") {
246
					var fillStyle = dojo.lang.shallowCopy(dojo.gfx.defaultPattern, true);
247
					fillStyle.width = dojo.gfx.vml.pt2px(fo.size.x);
248
					fillStyle.height = dojo.gfx.vml.pt2px(fo.size.y);
249
					fillStyle.x = fo.origin.x * fillStyle.width;
250
					fillStyle.y = fo.origin.y * fillStyle.height;
251
					fillStyle.src = fo.src;
252
				} else {
253
					if (fo.on && rawNode.fillcolor) {
254
						fillStyle = new dojo.gfx.color.Color(rawNode.fillcolor + "");
255
						fillStyle.a = fo.opacity;
256
					}
257
				}
258
			}
259
		}
260
	}
261
	return fillStyle;
262
}, attachStroke:function (rawNode) {
263
	var strokeStyle = dojo.lang.shallowCopy(dojo.gfx.defaultStroke, true);
264
	if (rawNode && rawNode.stroked) {
265
		strokeStyle.color = new dojo.gfx.color.Color(rawNode.strokecolor.value);
266
		dojo.debug("We are expecting an .75pt here, instead of strokeweight = " + rawNode.strokeweight);
267
		strokeStyle.width = dojo.gfx.vml.normalizedLength(rawNode.strokeweight + "");
268
		strokeStyle.color.a = rawNode.stroke.opacity;
269
		strokeStyle.cap = this._translate(this._capMapReversed, rawNode.stroke.endcap);
270
		strokeStyle.join = rawNode.stroke.joinstyle == "miter" ? rawNode.stroke.miterlimit : rawNode.stroke.joinstyle;
271
	} else {
272
		return null;
273
	}
274
	return strokeStyle;
275
}, attachTransform:function (rawNode) {
276
	var matrix = {};
277
	if (rawNode) {
278
		var s = rawNode.skew;
279
		matrix.xx = s.matrix.xtox;
280
		matrix.xy = s.matrix.ytox;
281
		matrix.yx = s.matrix.xtoy;
282
		matrix.yy = s.matrix.ytoy;
283
		matrix.dx = dojo.gfx.vml.pt2px(s.offset.x);
284
		matrix.dy = dojo.gfx.vml.pt2px(s.offset.y);
285
	}
286
	return dojo.gfx.matrix.normalize(matrix);
287
}, attach:function (rawNode) {
288
	if (rawNode) {
289
		this.rawNode = rawNode;
290
		this.shape = this.attachShape(rawNode);
291
		this.fillStyle = this.attachFill(rawNode);
292
		this.strokeStyle = this.attachStroke(rawNode);
293
		this.matrix = this.attachTransform(rawNode);
294
	}
295
}});
296
dojo.declare("dojo.gfx.Group", dojo.gfx.shape.VirtualGroup, {add:function (shape) {
297
	if (this != shape.getParent()) {
298
		this.rawNode.appendChild(shape.rawNode);
299
		dojo.gfx.Group.superclass.add.apply(this, arguments);
300
	}
301
	return this;
302
}, remove:function (shape, silently) {
303
	if (this == shape.getParent()) {
304
		if (this.rawNode == shape.rawNode.parentNode) {
305
			this.rawNode.removeChild(shape.rawNode);
306
		}
307
		dojo.gfx.Group.superclass.remove.apply(this, arguments);
308
	}
309
	return this;
310
}, attach:function (rawNode) {
311
	if (rawNode) {
312
		this.rawNode = rawNode;
313
		this.shape = null;
314
		this.fillStyle = null;
315
		this.strokeStyle = null;
316
		this.matrix = null;
317
	}
318
}});
319
dojo.gfx.Group.nodeType = "group";
320
var zIndex = {moveToFront:function () {
321
	this.rawNode.parentNode.appendChild(this.rawNode);
322
	return this;
323
}, moveToBack:function () {
324
	this.rawNode.parentNode.insertBefore(this.rawNode, this.rawNode.parentNode.firstChild);
325
	return this;
326
}};
327
dojo.lang.extend(dojo.gfx.Shape, zIndex);
328
dojo.lang.extend(dojo.gfx.Group, zIndex);
329
delete zIndex;
330
dojo.declare("dojo.gfx.Rect", dojo.gfx.shape.Rect, {attachShape:function (rawNode) {
331
	var arcsize = rawNode.outerHTML.match(/arcsize = \"(\d*\.?\d+[%f]?)\"/)[1];
332
	arcsize = (arcsize.indexOf("%") >= 0) ? parseFloat(arcsize) / 100 : dojo.gfx.vml._parseFloat(arcsize);
333
	var style = rawNode.style;
334
	var width = parseFloat(style.width);
335
	var height = parseFloat(style.height);
336
	var o = dojo.gfx.makeParameters(dojo.gfx.defaultRect, {x:parseInt(style.left), y:parseInt(style.top), width:width, height:height, r:Math.min(width, height) * arcsize});
337
	return o;
338
}, setShape:function (newShape) {
339
	var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape);
340
	this.bbox = null;
341
	var style = this.rawNode.style;
342
	style.left = shape.x.toFixed();
343
	style.top = shape.y.toFixed();
344
	style.width = (typeof (shape.width) == "string" && shape.width.indexOf("%") >= 0) ? shape.width : shape.width.toFixed();
345
	style.height = (typeof (shape.width) == "string" && shape.height.indexOf("%") >= 0) ? shape.height : shape.height.toFixed();
346
	var r = Math.min(1, (shape.r / Math.min(parseFloat(shape.width), parseFloat(shape.height)))).toFixed(8);
347
	var parent = this.rawNode.parentNode;
348
	var before = null;
349
	if (parent) {
350
		if (parent.lastChild != this.rawNode) {
351
			for (var i = 0; i < parent.childNodes.length; ++i) {
352
				if (parent.childNodes[i] == this.rawNode) {
353
					before = parent.childNodes[i + 1];
354
					break;
355
				}
356
			}
357
		}
358
		parent.removeChild(this.rawNode);
359
	}
360
	this.rawNode.arcsize = r;
361
	if (parent) {
362
		if (before) {
363
			parent.insertBefore(this.rawNode, before);
364
		} else {
365
			parent.appendChild(this.rawNode);
366
		}
367
	}
368
	return this.setTransform(this.matrix);
369
}});
370
dojo.gfx.Rect.nodeType = "roundrect";
371
dojo.declare("dojo.gfx.Ellipse", dojo.gfx.shape.Ellipse, {attachShape:function (rawNode) {
372
	var style = this.rawNode.style;
373
	var rx = parseInt(style.width) / 2;
374
	var ry = parseInt(style.height) / 2;
375
	var o = dojo.gfx.makeParameters(dojo.gfx.defaultEllipse, {cx:parseInt(style.left) + rx, cy:parseInt(style.top) + ry, rx:rx, ry:ry});
376
	return o;
377
}, setShape:function (newShape) {
378
	var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape);
379
	this.bbox = null;
380
	var style = this.rawNode.style;
381
	style.left = (shape.cx - shape.rx).toFixed();
382
	style.top = (shape.cy - shape.ry).toFixed();
383
	style.width = (shape.rx * 2).toFixed();
384
	style.height = (shape.ry * 2).toFixed();
385
	return this.setTransform(this.matrix);
386
}});
387
dojo.gfx.Ellipse.nodeType = "oval";
388
dojo.declare("dojo.gfx.Circle", dojo.gfx.shape.Circle, {attachShape:function (rawNode) {
389
	var style = this.rawNode.style;
390
	var r = parseInt(style.width) / 2;
391
	var o = dojo.gfx.makeParameters(dojo.gfx.defaultCircle, {cx:parseInt(style.left) + r, cy:parseInt(style.top) + r, r:r});
392
	return o;
393
}, setShape:function (newShape) {
394
	var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape);
395
	this.bbox = null;
396
	var style = this.rawNode.style;
397
	style.left = (shape.cx - shape.r).toFixed();
398
	style.top = (shape.cy - shape.r).toFixed();
399
	style.width = (shape.r * 2).toFixed();
400
	style.height = (shape.r * 2).toFixed();
401
	return this;
402
}});
403
dojo.gfx.Circle.nodeType = "oval";
404
dojo.declare("dojo.gfx.Line", dojo.gfx.shape.Line, function (rawNode) {
405
	if (rawNode) {
406
		rawNode.setAttribute("dojoGfxType", "line");
407
	}
408
}, {attachShape:function (rawNode) {
409
	var p = rawNode.path.v.match(dojo.gfx.pathRegExp);
410
	var shape = {};
411
	do {
412
		if (p.length < 7 || p[0] != "m" || p[3] != "l" || p[6] != "e") {
413
			break;
414
		}
415
		shape.x1 = parseInt(p[1]);
416
		shape.y1 = parseInt(p[2]);
417
		shape.x2 = parseInt(p[4]);
418
		shape.y2 = parseInt(p[5]);
419
	} while (false);
420
	return dojo.gfx.makeParameters(dojo.gfx.defaultLine, shape);
421
}, setShape:function (newShape) {
422
	var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape);
423
	this.bbox = null;
424
	this.rawNode.path.v = "m" + shape.x1.toFixed() + " " + shape.y1.toFixed() + "l" + shape.x2.toFixed() + " " + shape.y2.toFixed() + "e";
425
	return this.setTransform(this.matrix);
426
}});
427
dojo.gfx.Line.nodeType = "shape";
428
dojo.declare("dojo.gfx.Polyline", dojo.gfx.shape.Polyline, function (rawNode) {
429
	if (rawNode) {
430
		rawNode.setAttribute("dojoGfxType", "polyline");
431
	}
432
}, {attachShape:function (rawNode) {
433
	var shape = dojo.lang.shallowCopy(dojo.gfx.defaultPolyline, true);
434
	var p = rawNode.path.v.match(dojo.gfx.pathRegExp);
435
	do {
436
		if (p.length < 3 || p[0] != "m") {
437
			break;
438
		}
439
		var x = parseInt(p[0]);
440
		var y = parseInt(p[1]);
441
		if (isNaN(x) || isNaN(y)) {
442
			break;
443
		}
444
		shape.points.push({x:x, y:y});
445
		if (p.length < 6 || p[3] != "l") {
446
			break;
447
		}
448
		for (var i = 4; i < p.length; i += 2) {
449
			x = parseInt(p[i]);
450
			y = parseInt(p[i + 1]);
451
			if (isNaN(x) || isNaN(y)) {
452
				break;
453
			}
454
			shape.points.push({x:x, y:y});
455
		}
456
	} while (false);
457
	return shape;
458
}, setShape:function (points, closed) {
459
	if (points && points instanceof Array) {
460
		this.shape = dojo.gfx.makeParameters(this.shape, {points:points});
461
		if (closed && this.shape.points.length) {
462
			this.shape.points.push(this.shape.points[0]);
463
		}
464
	} else {
465
		this.shape = dojo.gfx.makeParameters(this.shape, points);
466
	}
467
	this.bbox = null;
468
	var attr = [];
469
	var p = this.shape.points;
470
	if (p.length > 0) {
471
		attr.push("m");
472
		attr.push(p[0].x.toFixed());
473
		attr.push(p[0].y.toFixed());
474
		if (p.length > 1) {
475
			attr.push("l");
476
			for (var i = 1; i < p.length; ++i) {
477
				attr.push(p[i].x.toFixed());
478
				attr.push(p[i].y.toFixed());
479
			}
480
		}
481
	}
482
	attr.push("e");
483
	this.rawNode.path.v = attr.join(" ");
484
	return this.setTransform(this.matrix);
485
}});
486
dojo.gfx.Polyline.nodeType = "shape";
487
dojo.declare("dojo.gfx.Image", dojo.gfx.shape.Image, {getEventSource:function () {
488
	return this.rawNode ? this.rawNode.firstChild : null;
489
}, attachShape:function (rawNode) {
490
	var shape = dojo.lang.shallowCopy(dojo.gfx.defaultImage, true);
491
	shape.src = rawNode.firstChild.src;
492
	return shape;
493
}, setShape:function (newShape) {
494
	var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape);
495
	this.bbox = null;
496
	var firstChild = this.rawNode.firstChild;
497
	firstChild.src = shape.src;
498
	if (shape.width || shape.height) {
499
		firstChild.style.width = shape.width;
500
		firstChild.style.height = shape.height;
501
	}
502
	return this.setTransform(this.matrix);
503
}, setStroke:function () {
504
	return this;
505
}, setFill:function () {
506
	return this;
507
}, attachStroke:function (rawNode) {
508
	return null;
509
}, attachFill:function (rawNode) {
510
	return null;
511
}, attachTransform:function (rawNode) {
512
	var matrix = {};
513
	if (rawNode) {
514
		var m = rawNode.filters["DXImageTransform.Microsoft.Matrix"];
515
		matrix.xx = m.M11;
516
		matrix.xy = m.M12;
517
		matrix.yx = m.M21;
518
		matrix.yy = m.M22;
519
		matrix.dx = m.Dx;
520
		matrix.dy = m.Dy;
521
	}
522
	return dojo.gfx.matrix.normalize(matrix);
523
}, _applyTransform:function () {
524
	var matrix = this._getRealMatrix();
525
	if (!matrix) {
526
		return this;
527
	}
528
	with (this.rawNode.filters["DXImageTransform.Microsoft.Matrix"]) {
529
		M11 = matrix.xx;
530
		M12 = matrix.xy;
531
		M21 = matrix.yx;
532
		M22 = matrix.yy;
533
		Dx = matrix.dx;
534
		Dy = matrix.dy;
535
	}
536
	return this;
537
}});
538
dojo.gfx.Image.nodeType = "image";
539
dojo.gfx.path._calcArc = function (alpha) {
540
	var cosa = Math.cos(alpha);
541
	var sina = Math.sin(alpha);
542
	var p2 = {x:cosa + (4 / 3) * (1 - cosa), y:sina - (4 / 3) * cosa * (1 - cosa) / sina};
543
	return {s:{x:cosa, y:sina}, c1:p2, c2:{x:p2.x, y:-p2.y}, e:{x:cosa, y:-sina}};
544
};
545
dojo.declare("dojo.gfx.Path", dojo.gfx.path.Path, function (rawNode) {
546
	if (rawNode) {
547
		rawNode.setAttribute("dojoGfxType", "path");
548
	}
549
	this.vmlPath = "";
550
	this.lastControl = {};
551
}, {_updateWithSegment:function (segment) {
552
	var last = dojo.lang.shallowCopy(this.last);
553
	dojo.gfx.Path.superclass._updateWithSegment.apply(this, arguments);
554
	var path = this[this.renderers[segment.action]](segment, last);
555
	if (typeof (this.vmlPath) == "string") {
556
		this.vmlPath += path.join("");
557
	} else {
558
		this.vmlPath = this.vmlPath.concat(path);
559
	}
560
	if (typeof (this.vmlPath) == "string") {
561
		this.rawNode.path.v = this.vmlPath + " e";
562
	}
563
}, attachShape:function (rawNode) {
564
	var shape = dojo.lang.shallowCopy(dojo.gfx.defaultPath, true);
565
	var p = rawNode.path.v.match(dojo.gfx.pathRegExp);
566
	var t = [], skip = false;
567
	for (var i = 0; i < p.length; ++p) {
568
		var s = p[i];
569
		if (s in this._pathVmlToSvgMap) {
570
			skip = false;
571
			t.push(this._pathVmlToSvgMap[s]);
572
		} else {
573
			if (!skip) {
574
				var n = parseInt(s);
575
				if (isNaN(n)) {
576
					skip = true;
577
				} else {
578
					t.push(n);
579
				}
580
			}
581
		}
582
	}
583
	if (t.length) {
584
		shape.path = t.join(" ");
585
	}
586
	return shape;
587
}, setShape:function (newShape) {
588
	this.vmlPath = [];
589
	this.lastControl = {};
590
	dojo.gfx.Path.superclass.setShape.apply(this, arguments);
591
	this.vmlPath = this.vmlPath.join("");
592
	this.rawNode.path.v = this.vmlPath + " e";
593
	return this;
594
}, _pathVmlToSvgMap:{m:"M", l:"L", t:"m", r:"l", c:"C", v:"c", qb:"Q", x:"z", e:""}, renderers:{M:"_moveToA", m:"_moveToR", L:"_lineToA", l:"_lineToR", H:"_hLineToA", h:"_hLineToR", V:"_vLineToA", v:"_vLineToR", C:"_curveToA", c:"_curveToR", S:"_smoothCurveToA", s:"_smoothCurveToR", Q:"_qCurveToA", q:"_qCurveToR", T:"_qSmoothCurveToA", t:"_qSmoothCurveToR", A:"_arcTo", a:"_arcTo", Z:"_closePath", z:"_closePath"}, _addArgs:function (path, args, from, upto) {
595
	if (typeof (upto) == "undefined") {
596
		upto = args.length;
597
	}
598
	if (typeof (from) == "undefined") {
599
		from = 0;
600
	}
601
	for (var i = from; i < upto; ++i) {
602
		path.push(" ");
603
		path.push(args[i].toFixed());
604
	}
605
}, _addArgsAdjusted:function (path, last, args, from, upto) {
606
	if (typeof (upto) == "undefined") {
607
		upto = args.length;
608
	}
609
	if (typeof (from) == "undefined") {
610
		from = 0;
611
	}
612
	for (var i = from; i < upto; i += 2) {
613
		path.push(" ");
614
		path.push((last.x + args[i]).toFixed());
615
		path.push(" ");
616
		path.push((last.y + args[i + 1]).toFixed());
617
	}
618
}, _moveToA:function (segment) {
619
	var p = [" m"];
620
	var n = segment.args;
621
	var l = n.length;
622
	if (l == 2) {
623
		this._addArgs(p, n);
624
	} else {
625
		this._addArgs(p, n, 0, 2);
626
		p.push(" l");
627
		this._addArgs(p, n, 2);
628
	}
629
	this.lastControl = {};
630
	return p;
631
}, _moveToR:function (segment, last) {
632
	var p = ["x" in last ? " t" : " m"];
633
	var n = segment.args;
634
	var l = n.length;
635
	if (l == 2) {
636
		this._addArgs(p, n);
637
	} else {
638
		this._addArgs(p, n, 0, 2);
639
		p.push(" r");
640
		this._addArgs(p, n, 2);
641
	}
642
	this.lastControl = {};
643
	return p;
644
}, _lineToA:function (segment) {
645
	var p = [" l"];
646
	this._addArgs(p, segment.args);
647
	this.lastControl = {};
648
	return p;
649
}, _lineToR:function (segment) {
650
	var p = [" r"];
651
	this._addArgs(p, segment.args);
652
	this.lastControl = {};
653
	return p;
654
}, _hLineToA:function (segment, last) {
655
	var p = [" l"];
656
	var n = segment.args;
657
	var l = n.length;
658
	var y = " " + last.y.toFixed();
659
	for (var i = 0; i < l; ++i) {
660
		p.push(" ");
661
		p.push(n[i].toFixed());
662
		p.push(y);
663
	}
664
	this.lastControl = {};
665
	return p;
666
}, _hLineToR:function (segment) {
667
	var p = [" r"];
668
	var n = segment.args;
669
	var l = n.length;
670
	for (var i = 0; i < l; ++i) {
671
		p.push(" ");
672
		p.push(n[i].toFixed());
673
		p.push(" 0");
674
	}
675
	this.lastControl = {};
676
	return p;
677
}, _vLineToA:function (segment, last) {
678
	var p = [" l"];
679
	var n = segment.args;
680
	var l = n.length;
681
	var x = " " + last.x.toFixed();
682
	for (var i = 0; i < l; ++i) {
683
		p.push(x);
684
		p.push(" ");
685
		p.push(n[i].toFixed());
686
	}
687
	this.lastControl = {};
688
	return p;
689
}, _vLineToR:function (segment) {
690
	var p = [" r"];
691
	var n = segment.args;
692
	var l = n.length;
693
	for (var i = 0; i < l; ++i) {
694
		p.push(" 0 ");
695
		p.push(n[i].toFixed());
696
	}
697
	this.lastControl = {};
698
	return p;
699
}, _curveToA:function (segment) {
700
	var p = [];
701
	var n = segment.args;
702
	var l = n.length;
703
	for (var i = 0; i < l; i += 6) {
704
		p.push(" c");
705
		this._addArgs(p, n, i, i + 6);
706
	}
707
	this.lastControl = {x:n[l - 4], y:n[l - 3], type:"C"};
708
	return p;
709
}, _curveToR:function (segment, last) {
710
	var p = [];
711
	var n = segment.args;
712
	var l = n.length;
713
	for (var i = 0; i < l; i += 6) {
714
		p.push(" v");
715
		this._addArgs(p, n, i, i + 6);
716
		this.lastControl = {x:last.x + n[i + 2], y:last.y + n[i + 3]};
717
		last.x += n[i + 4];
718
		last.y += n[i + 5];
719
	}
720
	this.lastControl.type = "C";
721
	return p;
722
}, _smoothCurveToA:function (segment, last) {
723
	var p = [];
724
	var n = segment.args;
725
	var l = n.length;
726
	for (var i = 0; i < l; i += 4) {
727
		p.push(" c");
728
		if (this.lastControl.type == "C") {
729
			this._addArgs(p, [2 * last.x - this.lastControl.x, 2 * last.y - this.lastControl.y]);
730
		} else {
731
			this._addArgs(p, [last.x, last.y]);
732
		}
733
		this._addArgs(p, n, i, i + 4);
734
	}
735
	this.lastControl = {x:n[l - 4], y:n[l - 3], type:"C"};
736
	return p;
737
}, _smoothCurveToR:function (segment, last) {
738
	var p = [];
739
	var n = segment.args;
740
	var l = n.length;
741
	for (var i = 0; i < l; i += 4) {
742
		p.push(" v");
743
		if (this.lastControl.type == "C") {
744
			this._addArgs(p, [last.x - this.lastControl.x, last.y - this.lastControl.y]);
745
		} else {
746
			this._addArgs(p, [0, 0]);
747
		}
748
		this._addArgs(p, n, i, i + 4);
749
		this.lastControl = {x:last.x + n[i], y:last.y + n[i + 1]};
750
		last.x += n[i + 2];
751
		last.y += n[i + 3];
752
	}
753
	this.lastControl.type = "C";
754
	return p;
755
}, _qCurveToA:function (segment) {
756
	var p = [];
757
	var n = segment.args;
758
	var l = n.length;
759
	for (var i = 0; i < l; i += 4) {
760
		p.push(" qb");
761
		this._addArgs(p, n, i, i + 4);
762
	}
763
	this.lastControl = {x:n[l - 4], y:n[l - 3], type:"Q"};
764
	return p;
765
}, _qCurveToR:function (segment, last) {
766
	var p = [];
767
	var n = segment.args;
768
	var l = n.length;
769
	for (var i = 0; i < l; i += 4) {
770
		p.push(" qb");
771
		this._addArgsAdjusted(p, last, n, i, i + 4);
772
		this.lastControl = {x:last.x + n[i], y:last.y + n[i + 1]};
773
		last.x += n[i + 2];
774
		last.y += n[i + 3];
775
	}
776
	this.lastControl.type = "Q";
777
	return p;
778
}, _qSmoothCurveToA:function (segment, last) {
779
	var p = [];
780
	var n = segment.args;
781
	var l = n.length;
782
	for (var i = 0; i < l; i += 2) {
783
		p.push(" qb");
784
		if (this.lastControl.type == "Q") {
785
			this._addArgs(p, [this.lastControl.x = 2 * last.x - this.lastControl.x, this.lastControl.y = 2 * last.y - this.lastControl.y]);
786
		} else {
787
			this._addArgs(p, [this.lastControl.x = last.x, this.lastControl.y = last.y]);
788
		}
789
		this._addArgs(p, n, i, i + 2);
790
	}
791
	this.lastControl.type = "Q";
792
	return p;
793
}, _qSmoothCurveToR:function (segment, last) {
794
	var p = [];
795
	var n = segment.args;
796
	var l = n.length;
797
	for (var i = 0; i < l; i += 2) {
798
		p.push(" qb");
799
		if (this.lastControl.type == "Q") {
800
			this._addArgs(p, [this.lastControl.x = 2 * last.x - this.lastControl.x, this.lastControl.y = 2 * last.y - this.lastControl.y]);
801
		} else {
802
			this._addArgs(p, [this.lastControl.x = last.x, this.lastControl.y = last.y]);
803
		}
804
		this._addArgsAdjusted(p, last, n, i, i + 2);
805
	}
806
	this.lastControl.type = "Q";
807
	return p;
808
}, _PI4:Math.PI / 4, _curvePI4:dojo.gfx.path._calcArc(Math.PI / 8), _calcArcTo:function (path, last, rx, ry, xRotg, large, cw, x, y) {
809
	var m = dojo.gfx.matrix;
810
	var xRot = -dojo.math.degToRad(xRotg);
811
	var rx2 = rx * rx;
812
	var ry2 = ry * ry;
813
	var pa = m.multiplyPoint(m.rotate(-xRot), {x:(last.x - x) / 2, y:(last.y - y) / 2});
814
	var pax2 = pa.x * pa.x;
815
	var pay2 = pa.y * pa.y;
816
	var c1 = Math.sqrt((rx2 * ry2 - rx2 * pay2 - ry2 * pax2) / (rx2 * pay2 + ry2 * pax2));
817
	var ca = {x:c1 * rx * pa.y / ry, y:-c1 * ry * pa.x / rx};
818
	if (large == cw) {
819
		ca = {x:-ca.x, y:-ca.y};
820
	}
821
	var c = m.multiplyPoint([m.translate((last.x + x) / 2, (last.y + y) / 2), m.rotate(xRot)], ca);
822
	var startAngle = Math.atan2(c.y - last.y, last.x - c.x) - xRot;
823
	var endAngle = Math.atan2(c.y - y, x - c.x) - xRot;
824
	var theta = cw ? startAngle - endAngle : endAngle - startAngle;
825
	if (theta < 0) {
826
		theta += this._2PI;
827
	} else {
828
		if (theta > this._2PI) {
829
			theta = this._2PI;
830
		}
831
	}
832
	var elliptic_transform = m.normalize([m.translate(c.x, c.y), m.rotate(xRot), m.scale(rx, ry)]);
833
	var alpha = this._PI4 / 2;
834
	var curve = this._curvePI4;
835
	var step = cw ? -alpha : alpha;
836
	for (var angle = theta; angle > 0; angle -= this._PI4) {
837
		if (angle < this._PI4) {
838
			alpha = angle / 2;
839
			curve = dojo.gfx.path._calcArc(alpha);
840
			step = cw ? -alpha : alpha;
841
		}
842
		var c1, c2, e;
843
		var M = m.normalize([elliptic_transform, m.rotate(startAngle + step)]);
844
		if (cw) {
845
			c1 = m.multiplyPoint(M, curve.c2);
846
			c2 = m.multiplyPoint(M, curve.c1);
847
			e = m.multiplyPoint(M, curve.s);
848
		} else {
849
			c1 = m.multiplyPoint(M, curve.c1);
850
			c2 = m.multiplyPoint(M, curve.c2);
851
			e = m.multiplyPoint(M, curve.e);
852
		}
853
		path.push(" c");
854
		this._addArgs(path, [c1.x, c1.y, c2.x, c2.y, e.x, e.y]);
855
		startAngle += 2 * step;
856
	}
857
}, _arcTo:function (segment, last) {
858
	var p = [];
859
	var n = segment.args;
860
	var l = n.length;
861
	var relative = segment.action == "a";
862
	for (var i = 0; i < l; i += 7) {
863
		var x1 = n[i + 5];
864
		var y1 = n[i + 6];
865
		if (relative) {
866
			x1 += last.x;
867
			y1 += last.y;
868
		}
869
		this._calcArcTo(p, last, n[i], n[i + 1], n[i + 2], n[i + 3] ? 1 : 0, n[i + 4] ? 1 : 0, x1, y1);
870
		last = {x:x1, y:y1};
871
	}
872
	this.lastControl = {};
873
	return p;
874
}, _closePath:function () {
875
	this.lastControl = {};
876
	return ["x"];
877
}});
878
dojo.gfx.Path.nodeType = "shape";
879
dojo.gfx._creators = {createPath:function (path) {
880
	return this.createObject(dojo.gfx.Path, path, true);
881
}, createRect:function (rect) {
882
	return this.createObject(dojo.gfx.Rect, rect);
883
}, createCircle:function (circle) {
884
	return this.createObject(dojo.gfx.Circle, circle);
885
}, createEllipse:function (ellipse) {
886
	return this.createObject(dojo.gfx.Ellipse, ellipse);
887
}, createLine:function (line) {
888
	return this.createObject(dojo.gfx.Line, line, true);
889
}, createPolyline:function (points) {
890
	return this.createObject(dojo.gfx.Polyline, points, true);
891
}, createImage:function (image) {
892
	if (!this.rawNode) {
893
		return null;
894
	}
895
	var shape = new dojo.gfx.Image();
896
	var node = document.createElement("div");
897
	node.style.position = "relative";
898
	node.style.width = this.rawNode.style.width;
899
	node.style.height = this.rawNode.style.height;
900
	node.style.filter = "progid:DXImageTransform.Microsoft.Matrix(M11=1, M12=0, M21=0, M22=1, Dx=0, Dy=0)";
901
	var img = document.createElement("img");
902
	node.appendChild(img);
903
	shape.setRawNode(node);
904
	this.rawNode.appendChild(node);
905
	shape.setShape(image);
906
	this.add(shape);
907
	return shape;
908
}, createGroup:function () {
909
	return this.createObject(dojo.gfx.Group, null, true);
910
}, createObject:function (shapeType, rawShape, overrideSize) {
911
	if (!this.rawNode) {
912
		return null;
913
	}
914
	var shape = new shapeType();
915
	var node = document.createElement("v:" + shapeType.nodeType);
916
	shape.setRawNode(node);
917
	this.rawNode.appendChild(node);
918
	if (overrideSize) {
919
		this._overrideSize(node);
920
	}
921
	shape.setShape(rawShape);
922
	this.add(shape);
923
	return shape;
924
}, _overrideSize:function (node) {
925
	node.style.width = this.rawNode.style.width;
926
	node.style.height = this.rawNode.style.height;
927
	node.coordsize = parseFloat(node.style.width) + " " + parseFloat(node.style.height);
928
}};
929
dojo.lang.extend(dojo.gfx.Group, dojo.gfx._creators);
930
dojo.lang.extend(dojo.gfx.Surface, dojo.gfx._creators);
931
delete dojo.gfx._creators;
932
dojo.gfx.attachNode = function (node) {
933
	if (!node) {
934
		return null;
935
	}
936
	var s = null;
937
	switch (node.tagName.toLowerCase()) {
938
	  case dojo.gfx.Rect.nodeType:
939
		s = new dojo.gfx.Rect();
940
		break;
941
	  case dojo.gfx.Ellipse.nodeType:
942
		s = (node.style.width == node.style.height) ? new dojo.gfx.Circle() : new dojo.gfx.Ellipse();
943
		break;
944
	  case dojo.gfx.Path.nodeType:
945
		switch (node.getAttribute("dojoGfxType")) {
946
		  case "line":
947
			s = new dojo.gfx.Line();
948
			break;
949
		  case "polyline":
950
			s = new dojo.gfx.Polyline();
951
			break;
952
		  case "path":
953
			s = new dojo.gfx.Path();
954
			break;
955
		}
956
		break;
957
	  case dojo.gfx.Image.nodeType:
958
		s = new dojo.gfx.Image();
959
		break;
960
	  default:
961
		dojo.debug("FATAL ERROR! tagName = " + node.tagName);
962
	}
963
	s.attach(node);
964
	return s;
965
};
966
dojo.lang.extend(dojo.gfx.Surface, {setDimensions:function (width, height) {
967
	if (!this.rawNode) {
968
		return this;
969
	}
970
	this.rawNode.style.width = width;
971
	this.rawNode.style.height = height;
972
	this.rawNode.coordsize = width + " " + height;
973
	return this;
974
}, getDimensions:function () {
975
	return this.rawNode ? {width:this.rawNode.style.width, height:this.rawNode.style.height} : null;
976
}, add:function (shape) {
977
	var oldParent = shape.getParent();
978
	if (this != oldParent) {
979
		this.rawNode.appendChild(shape.rawNode);
980
		if (oldParent) {
981
			oldParent.remove(shape, true);
982
		}
983
		shape._setParent(this, null);
984
	}
985
	return this;
986
}, remove:function (shape, silently) {
987
	if (this == shape.getParent()) {
988
		if (this.rawNode == shape.rawNode.parentNode) {
989
			this.rawNode.removeChild(shape.rawNode);
990
		}
991
		shape._setParent(null, null);
992
	}
993
	return this;
994
}});
995
dojo.gfx.createSurface = function (parentNode, width, height) {
996
	var s = new dojo.gfx.Surface();
997
	s.rawNode = document.createElement("v:group");
998
	s.rawNode.style.width = width ? width : "100%";
999
	s.rawNode.style.height = height ? height : "100%";
1000
	s.rawNode.coordsize = (width && height) ? (parseFloat(width) + " " + parseFloat(height)) : "100% 100%";
1001
	s.rawNode.coordorigin = "0 0";
1002
	dojo.byId(parentNode).appendChild(s.rawNode);
1003
	return s;
1004
};
1005
dojo.gfx.attachSurface = function (node) {
1006
	var s = new dojo.gfx.Surface();
1007
	s.rawNode = node;
1008
	return s;
1009
};
1010