Debian Codegraph @

dojox/gfx/vml.js

raw symbols SCIP
1 define(["dojo/_base/lang", "dojo/_base/declare", "dojo/_base/array", "dojo/_base/Color", "dojo/_base/sniff",
2 "dojo/_base/config", "dojo/dom", "dojo/dom-geometry", "dojo/_base/kernel",
3 "./_base", "./shape", "./path", "./arc", "./gradient", "./matrix"],
4 function(lang, declare, arr, Color, has, config, dom, domGeom, kernel, g, gs, pathLib, arcLib, gradient, m){
5 var vml = g.vml = {
6 // summary:
7 // This the default graphics rendering bridge for IE6-7.
8 // This renderer is very slow. For best performance on IE6-8, use Silverlight plugin.
9 // IE9+ defaults to the standard W3C SVG renderer.
10
11 // TODO: Everything exported from this file should be inside these braces.
12 // For now, I'll just put the declarations needed for documentation.
13
14 // xmlns: String
15 // a VML's namespace
16
17 // text_alignment: Object
18 // mapping from SVG alignment to VML alignment
19 };
20
21 vml.xmlns = "urn:schemas-microsoft-com:vml";
22
23 document.namespaces.add("v", vml.xmlns);
24 var vmlElems = ["*", "group", "roundrect", "oval", "shape", "rect", "imagedata", "path", "textpath", "text"],
25 i = 0, l = 1, s = document.createStyleSheet();
26 if(has("ie") >= 8){
27 i = 1;
28 l = vmlElems.length;
29 }
30 for (; i < l; ++i) {
31 s.addRule("v\\:" + vmlElems[i], "behavior:url(#default#VML); display:inline-block");
32 }
33
34 vml.text_alignment = {start: "left", middle: "center", end: "right"};
35
36 vml._parseFloat = function(str) {
37 // summary:
38 // a helper function to parse VML-specific floating-point values
39 // str: String
40 // a representation of a floating-point number
41 return str.match(/^\d+f$/i) ? parseInt(str) / 65536 : parseFloat(str); // Number
42 };
43
44 vml._bool = {"t": 1, "true": 1};
45
46 vml._reparentEvents = function(dst, src){
47 for(var name in src){
48 if(name.substr(0, 2).toLowerCase() == "on"){
49 dst[name] = src[name];
50 src[name] = null;
51 }
52 }
53 };
54
55 vml.Shape = declare("dojox.gfx.vml.Shape", gs.Shape, {
56 // summary:
57 // VML-specific implementation of dojox/gfx/shape.Shape methods
58
59 setFill: function(fill){
60 // summary:
61 // sets a fill object (VML)
62 // fill: Object
63 // a fill object
64 // (see dojox/gfx.defaultLinearGradient,
65 // dojox/gfx.defaultRadialGradient,
66 // dojox/gfx.defaultPattern,
67 // or dojo/_base/Color)
68
69 if(!fill){
70 // don't fill
71 this.fillStyle = null;
72 this.rawNode.filled = "f";
73 return this;
74 }
75 var i, f, fo, a, s;
76 if(typeof fill == "object" && "type" in fill){
77 // gradient
78 switch(fill.type){
79 case "linear":
80 var matrix = this._getRealMatrix(), bbox = this.getBoundingBox(),
81 tbbox = this._getRealBBox ? this._getRealBBox() : this.getTransformedBoundingBox();
82 s = [];
83 if(this.fillStyle !== fill){
84 this.fillStyle = g.makeParameters(g.defaultLinearGradient, fill);
85 }
86 f = g.gradient.project(matrix, this.fillStyle,
87 {x: bbox.x, y: bbox.y},
88 {x: bbox.x + bbox.width, y: bbox.y + bbox.height},
89 tbbox[0], tbbox[2]);
90 a = f.colors;
91 if(a[0].offset.toFixed(5) != "0.00000"){
92 s.push("0 " + g.normalizeColor(a[0].color).toHex());
93 }
94 for(i = 0; i < a.length; ++i){
95 s.push(a[i].offset.toFixed(5) + " " + g.normalizeColor(a[i].color).toHex());
96 }
97 i = a.length - 1;
98 if(a[i].offset.toFixed(5) != "1.00000"){
99 s.push("1 " + g.normalizeColor(a[i].color).toHex());
100 }
101 fo = this.rawNode.fill;
102 fo.colors.value = s.join(";");
103 fo.method = "sigma";
104 fo.type = "gradient";
105 fo.angle = (270 - m._radToDeg(f.angle)) % 360;
106 fo.on = true;
107 break;
108 case "radial":
109 f = g.makeParameters(g.defaultRadialGradient, fill);
110 this.fillStyle = f;
111 var l = parseFloat(this.rawNode.style.left),
112 t = parseFloat(this.rawNode.style.top),
113 w = parseFloat(this.rawNode.style.width),
114 h = parseFloat(this.rawNode.style.height),
115 c = isNaN(w) ? 1 : 2 * f.r / w;
116 a = [];
117 // add a color at the offset 0 (1 in VML coordinates)
118 if(f.colors[0].offset > 0){
119 a.push({offset: 1, color: g.normalizeColor(f.colors[0].color)});
120 }
121 // massage colors
122 arr.forEach(f.colors, function(v, i){
123 a.push({offset: 1 - v.offset * c, color: g.normalizeColor(v.color)});
124 });
125 i = a.length - 1;
126 while(i >= 0 && a[i].offset < 0){ --i; }
127 if(i < a.length - 1){
128 // correct excessive colors
129 var q = a[i], p = a[i + 1];
130 p.color = Color.blendColors(q.color, p.color, q.offset / (q.offset - p.offset));
131 p.offset = 0;
132 while(a.length - i > 2) a.pop();
133 }
134 // set colors
135 i = a.length - 1, s = [];
136 if(a[i].offset > 0){
137 s.push("0 " + a[i].color.toHex());
138 }
139 for(; i >= 0; --i){
140 s.push(a[i].offset.toFixed(5) + " " + a[i].color.toHex());
141 }
142 fo = this.rawNode.fill;
143 fo.colors.value = s.join(";");
144 fo.method = "sigma";
145 fo.type = "gradientradial";
146 if(isNaN(w) || isNaN(h) || isNaN(l) || isNaN(t)){
147 fo.focusposition = "0.5 0.5";
148 }else{
149 fo.focusposition = ((f.cx - l) / w).toFixed(5) + " " + ((f.cy - t) / h).toFixed(5);
150 }
151 fo.focussize = "0 0";
152 fo.on = true;
153 break;
154 case "pattern":
155 f = g.makeParameters(g.defaultPattern, fill);
156 this.fillStyle = f;
157 fo = this.rawNode.fill;
158 fo.type = "tile";
159 fo.src = f.src;
160 if(f.width && f.height){
161 // in points
162 fo.size.x = g.px2pt(f.width);
163 fo.size.y = g.px2pt(f.height);
164 }
165 fo.alignShape = "f";
166 fo.position.x = 0;
167 fo.position.y = 0;
168 fo.origin.x = f.width ? f.x / f.width : 0;
169 fo.origin.y = f.height ? f.y / f.height : 0;
170 fo.on = true;
171 break;
172 }
173 this.rawNode.fill.opacity = 1;
174 return this;
175 }
176 // color object
177 this.fillStyle = g.normalizeColor(fill);
178 fo = this.rawNode.fill;
179 if(!fo){
180 fo = this.rawNode.ownerDocument.createElement("v:fill");
181 }
182 fo.method = "any";
183 fo.type = "solid";
184 fo.opacity = this.fillStyle.a;
185 var alphaFilter = this.rawNode.filters["DXImageTransform.Microsoft.Alpha"];
186 if(alphaFilter){
187 alphaFilter.opacity = Math.round(this.fillStyle.a * 100);
188 }
189 this.rawNode.fillcolor = this.fillStyle.toHex();
190 this.rawNode.filled = true;
191 return this; // self
192 },
193
194 setStroke: function(stroke){
195 // summary:
196 // sets a stroke object (VML)
197 // stroke: Object
198 // a stroke object
199 // (see dojox/gfx.defaultStroke)
200
201 if(!stroke){
202 // don't stroke
203 this.strokeStyle = null;
204 this.rawNode.stroked = "f";
205 return this;
206 }
207 // normalize the stroke
208 if(typeof stroke == "string" || lang.isArray(stroke) || stroke instanceof Color){
209 stroke = {color: stroke};
210 }
211 var s = this.strokeStyle = g.makeParameters(g.defaultStroke, stroke);
212 s.color = g.normalizeColor(s.color);
213 // generate attributes
214 var rn = this.rawNode;
215 rn.stroked = true;
216 rn.strokecolor = s.color.toCss();
217 rn.strokeweight = s.width + "px"; // TODO: should we assume that the width is always in pixels?
218 if(rn.stroke) {
219 rn.stroke.opacity = s.color.a;
220 rn.stroke.endcap = this._translate(this._capMap, s.cap);
221 if(typeof s.join == "number") {
222 rn.stroke.joinstyle = "miter";
223 rn.stroke.miterlimit = s.join;
224 }else{
225 rn.stroke.joinstyle = s.join;
226 // rn.stroke.miterlimit = s.width;
227 }
228 rn.stroke.dashstyle = s.style == "none" ? "Solid" : s.style;
229 }
230 return this; // self
231 },
232
233 _capMap: { butt: 'flat' },
234 _capMapReversed: { flat: 'butt' },
235
236 _translate: function(dict, value) {
237 return (value in dict) ? dict[value] : value;
238 },
239
240 _applyTransform: function() {
241 var matrix = this._getRealMatrix();
242 if(matrix){
243 var skew = this.rawNode.skew;
244 if(typeof skew == "undefined"){
245 for(var i = 0; i < this.rawNode.childNodes.length; ++i){
246 if(this.rawNode.childNodes[i].tagName == "skew"){
247 skew = this.rawNode.childNodes[i];
248 break;
249 }
250 }
251 }
252 if(skew){
253 skew.on = "f";
254 var mt = matrix.xx.toFixed(8) + " " + matrix.xy.toFixed(8) + " " +
255 matrix.yx.toFixed(8) + " " + matrix.yy.toFixed(8) + " 0 0",
256 offset = Math.floor(matrix.dx).toFixed() + "px " + Math.floor(matrix.dy).toFixed() + "px",
257 s = this.rawNode.style,
258 l = parseFloat(s.left),
259 t = parseFloat(s.top),
260 w = parseFloat(s.width),
261 h = parseFloat(s.height);
262 if(isNaN(l)) l = 0;
263 if(isNaN(t)) t = 0;
264 if(isNaN(w) || !w) w = 1;
265 if(isNaN(h) || !h) h = 1;
266 var origin = (-l / w - 0.5).toFixed(8) + " " + (-t / h - 0.5).toFixed(8);
267 skew.matrix = mt;
268 skew.origin = origin;
269 skew.offset = offset;
270 skew.on = true;
271 }
272 }
273 if(this.fillStyle && this.fillStyle.type == "linear"){
274 this.setFill(this.fillStyle);
275 }
276 if(this.clip){
277 this.setClip(this.clip);
278 }
279 return this;
280 },
281
282 _setDimensions: function(width, height){
283 // summary:
284 // sets the width and height of the rawNode,
285 // if the surface size has been changed
286 // width: String
287 // width in pixels
288 // height: String
289 // height in pixels
290
291 // default implementation does nothing
292 return this; // self
293 },
294
295 setRawNode: function(rawNode){
296 // summary:
297 // assigns and clears the underlying node that will represent this
298 // shape. Once set, transforms, gradients, etc, can be applied.
299 // (no fill & stroke by default)
300 rawNode.stroked = "f";
301 rawNode.filled = "f";
302 this.rawNode = rawNode;
303 this.rawNode.__gfxObject__ = this;
304 },
305
306 // move family
307
308 _moveToFront: function(){
309 // summary:
310 // moves a shape to front of its parent's list of shapes (VML)
311 this.rawNode.parentNode.appendChild(this.rawNode);
312 return this;
313 },
314 _moveToBack: function(){
315 // summary:
316 // moves a shape to back of its parent's list of shapes (VML)
317 var r = this.rawNode, p = r.parentNode, n = p.firstChild;
318 p.insertBefore(r, n);
319 if(n.tagName == "rect"){
320 // surface has a background rectangle, which position should be preserved
321 n.swapNode(r);
322 }
323 return this;
324 },
325
326 _getRealMatrix: function(){
327 // summary:
328 // returns the cumulative ("real") transformation matrix
329 // by combining the shape's matrix with its parent's matrix
330 return this.parentMatrix ? new m.Matrix2D([this.parentMatrix, this.matrix]) : this.matrix; // dojox/gfx/matrix.Matrix2D
331 },
332
333 setClip: function(clip){
334 // summary:
335 // sets the clipping area of this shape.
336 // description:
337 // This method overrides the dojox/gfx/shape.Shape.setClip() method. Only rectangular geometry is supported.
338 // clip: Object
339 // an object that defines the clipping geometry, or null to remove clip.
340 this.inherited(arguments);
341 var nodeStyle = this.rawNode.style;
342 if(!clip){
343 // remove clip
344 nodeStyle.position = "absolute";
345 nodeStyle.clip = "rect(0px "+nodeStyle.width+" "+nodeStyle.height+" 0px)";
346 }else{
347 if("width" in clip){
348 var matrix = this._getRealMatrix(),
349 l = parseFloat(nodeStyle.left),
350 t = parseFloat(nodeStyle.top);
351 if(isNaN(l)) l = 0;
352 if(isNaN(t)) t = 0;
353 // transform the clip with the shape transform to compute the correct w/h (e.g. after a scale)
354 var clipt = m.multiplyRectangle(matrix, clip);
355 var pt = m.multiplyPoint(matrix, {x:l,y:t});
356 // clip property is relative to the elt border box
357 nodeStyle.clip = "rect(" + Math.round(clipt.y-pt.y) + "px " + Math.round(clipt.x-pt.x + clipt.width ) + "px " +
358 Math.round(clipt.y-pt.y + clipt.height ) + "px " + Math.round(clipt.x -pt.x) + "px)";
359 }
360 }
361 return this;
362 }
363 });
364
365 vml.Group = declare("dojox.gfx.vml.Group", vml.Shape, {
366 // summary:
367 // a group shape (VML), which can be used
368 // to logically group shapes (e.g, to propagate matricies)
369 constructor: function(){
370 gs.Container._init.call(this);
371 },
372 // apply transformation
373 _applyTransform: function(){
374 // summary:
375 // applies a transformation matrix to a group
376 var matrix = this._getRealMatrix();
377 for(var i = 0; i < this.children.length; ++i){
378 this.children[i]._updateParentMatrix(matrix);
379 }
380 if(this.clip){
381 this.setClip(this.clip);
382 }
383 return this; // self
384 },
385 _setDimensions: function(width, height){
386 // summary:
387 // sets the width and height of the rawNode,
388 // if the surface size has been changed
389 // width: String
390 // width in pixels
391 // height: String
392 // height in pixels
393 var r = this.rawNode, rs = r.style,
394 bs = this.bgNode.style;
395 rs.width = width;
396 rs.height = height;
397 r.coordsize = width + " " + height;
398 bs.width = width;
399 bs.height = height;
400 for(var i = 0; i < this.children.length; ++i){
401 this.children[i]._setDimensions(width, height);
402 }
403 return this; // self
404 },
405 setClip: function(clip){
406 // summary:
407 // sets the clipping area of this shape.
408 // description:
409 // This method overrides the dojox/gfx/shape.Shape.setClip() method.
410 // clip: Object
411 // an object that defines the clipping geometry, or null to remove clip.
412
413 this.clip = clip;
414 var nodeStyle = this.rawNode.style;
415 if(!clip){
416 // remove clip
417 nodeStyle.position = "absolute";
418 nodeStyle.clip = "rect(0px "+nodeStyle.width+" "+nodeStyle.height+" 0px)";
419 }else if("width" in clip){
420 var matrix = this._getRealMatrix();
421 // transform the clip with group transform
422 var clipt = m.multiplyRectangle(matrix, clip);
423 // vml feature :-( ): if the group rawNode bbox x/y are < 0,
424 // need to adjust clip accordingly
425 var bbox = this.getBoundingBox();
426 bbox = bbox ? m.multiplyRectangle(matrix, bbox) : null;
427 var offx = bbox && bbox.x < 0 ? bbox.x : 0,
428 offy = bbox && bbox.y < 0 ? bbox.y : 0;
429 nodeStyle.position = "absolute";
430 nodeStyle.clip = "rect(" +
431 Math.round(clipt.y - offy) + "px " +
432 Math.round(clipt.x + clipt.width - offx) + "px " +
433 Math.round(clipt.y + clipt.height - offy) + "px " +
434 Math.round(clipt.x - offx) + "px)";
435 }
436 return this;
437 },
438 destroy: function(){
439 // summary:
440 // Releases all internal resources owned by this shape. Once this method has been called,
441 // the instance is considered disposed and should not be used anymore.
442 this.clear(true);
443 // avoid this.inherited
444 vml.Shape.prototype.destroy.apply(this, arguments);
445 }
446 });
447 vml.Group.nodeType = "group";
448
449 vml.Rect = declare("dojox.gfx.vml.Rect", [vml.Shape, gs.Rect], {
450 // summary:
451 // a rectangle shape (VML)
452 setShape: function(newShape){
453 // summary:
454 // sets a rectangle shape object (VML)
455 // newShape: Object
456 // a rectangle shape object
457 var shape = this.shape = g.makeParameters(this.shape, newShape);
458 this.bbox = null;
459 var r = Math.min(1, (shape.r / Math.min(parseFloat(shape.width), parseFloat(shape.height)))).toFixed(8);
460 // a workaround for the VML's arcsize bug: cannot read arcsize of an instantiated node
461 var parent = this.rawNode.parentNode, before = null;
462 if(parent){
463 if(parent.lastChild !== this.rawNode){
464 for(var i = 0; i < parent.childNodes.length; ++i){
465 if(parent.childNodes[i] === this.rawNode){
466 before = parent.childNodes[i + 1];
467 break;
468 }
469 }
470 }
471 parent.removeChild(this.rawNode);
472 }
473 if(has("ie") > 7){
474 var node = this.rawNode.ownerDocument.createElement("v:roundrect");
475 node.arcsize = r;
476 node.style.display = "inline-block";
477 vml._reparentEvents(node, this.rawNode);
478 this.rawNode = node;
479 this.rawNode.__gfxObject__ = this;
480 }else{
481 this.rawNode.arcsize = r;
482 }
483 if(parent){
484 if(before){
485 parent.insertBefore(this.rawNode, before);
486 }else{
487 parent.appendChild(this.rawNode);
488 }
489 }
490 var style = this.rawNode.style;
491 style.left = shape.x.toFixed();
492 style.top = shape.y.toFixed();
493 style.width = (typeof shape.width == "string" && shape.width.indexOf("%") >= 0) ? shape.width : Math.max(shape.width.toFixed(),0);
494 style.height = (typeof shape.height == "string" && shape.height.indexOf("%") >= 0) ? shape.height : Math.max(shape.height.toFixed(),0);
495 // set all necessary styles, which are lost by VML (yes, it's a VML's bug)
496 return this.setTransform(this.matrix).setFill(this.fillStyle).setStroke(this.strokeStyle); // self
497 }
498 });
499 vml.Rect.nodeType = "roundrect"; // use a roundrect so the stroke join type is respected
500
501 vml.Ellipse = declare("dojox.gfx.vml.Ellipse", [vml.Shape, gs.Ellipse], {
502 // summary:
503 // an ellipse shape (VML)
504 setShape: function(newShape){
505 // summary:
506 // sets an ellipse shape object (VML)
507 // newShape: Object
508 // an ellipse shape object
509 var shape = this.shape = g.makeParameters(this.shape, newShape);
510 this.bbox = null;
511 var style = this.rawNode.style;
512 style.left = (shape.cx - shape.rx).toFixed();
513 style.top = (shape.cy - shape.ry).toFixed();
514 style.width = (shape.rx * 2).toFixed();
515 style.height = (shape.ry * 2).toFixed();
516 return this.setTransform(this.matrix); // self
517 }
518 });
519 vml.Ellipse.nodeType = "oval";
520
521 vml.Circle = declare("dojox.gfx.vml.Circle", [vml.Shape, gs.Circle], {
522 // summary:
523 // a circle shape (VML)
524 setShape: function(newShape){
525 // summary:
526 // sets a circle shape object (VML)
527 // newShape: Object
528 // a circle shape object
529 var shape = this.shape = g.makeParameters(this.shape, newShape);
530 this.bbox = null;
531 var style = this.rawNode.style;
532 style.left = (shape.cx - shape.r).toFixed();
533 style.top = (shape.cy - shape.r).toFixed();
534 style.width = (shape.r * 2).toFixed();
535 style.height = (shape.r * 2).toFixed();
536 return this; // self
537 }
538 });
539 vml.Circle.nodeType = "oval";
540
541 vml.Line = declare("dojox.gfx.vml.Line", [vml.Shape, gs.Line], {
542 // summary:
543 // a line shape (VML)
544 constructor: function(rawNode){
545 if(rawNode) rawNode.setAttribute("dojoGfxType", "line");
546 },
547 setShape: function(newShape){
548 // summary:
549 // sets a line shape object (VML)
550 // newShape: Object
551 // a line shape object
552 var shape = this.shape = g.makeParameters(this.shape, newShape);
553 this.bbox = null;
554 this.rawNode.path.v = "m" + shape.x1.toFixed() + " " + shape.y1.toFixed() +
555 "l" + shape.x2.toFixed() + " " + shape.y2.toFixed() + "e";
556 return this.setTransform(this.matrix); // self
557 }
558 });
559 vml.Line.nodeType = "shape";
560
561 vml.Polyline = declare("dojox.gfx.vml.Polyline", [vml.Shape, gs.Polyline], {
562 // summary:
563 // a polyline/polygon shape (VML)
564 constructor: function(rawNode){
565 if(rawNode) rawNode.setAttribute("dojoGfxType", "polyline");
566 },
567 setShape: function(points, closed){
568 // summary:
569 // sets a polyline/polygon shape object (VML)
570 // points: Object|Array
571 // a polyline/polygon shape object, or an array of points
572 // closed: Boolean?
573 // if true, close the polyline explicitly
574 if(points && points instanceof Array){
575 this.shape = g.makeParameters(this.shape, { points: points });
576 if(closed && this.shape.points.length) this.shape.points.push(this.shape.points[0]);
577 }else{
578 this.shape = g.makeParameters(this.shape, points);
579 }
580 this.bbox = null;
581 this._normalizePoints();
582 var attr = [], p = this.shape.points;
583 if(p.length > 0){
584 attr.push("m");
585 attr.push(p[0].x.toFixed(), p[0].y.toFixed());
586 if(p.length > 1){
587 attr.push("l");
588 for(var i = 1; i < p.length; ++i){
589 attr.push(p[i].x.toFixed(), p[i].y.toFixed());
590 }
591 }
592 }
593 attr.push("e");
594 this.rawNode.path.v = attr.join(" ");
595 return this.setTransform(this.matrix); // self
596 }
597 });
598 vml.Polyline.nodeType = "shape";
599
600 vml.Image = declare("dojox.gfx.vml.Image", [vml.Shape, gs.Image], {
601 // summary:
602 // an image (VML)
603 setShape: function(newShape){
604 // summary:
605 // sets an image shape object (VML)
606 // newShape: Object
607 // an image shape object
608 var shape = this.shape = g.makeParameters(this.shape, newShape);
609 this.bbox = null;
610 this.rawNode.firstChild.src = shape.src;
611 return this.setTransform(this.matrix); // self
612 },
613 _applyTransform: function() {
614 var matrix = this._getRealMatrix(),
615 rawNode = this.rawNode,
616 s = rawNode.style,
617 shape = this.shape;
618 if(matrix){
619 matrix = m.multiply(matrix, {dx: shape.x, dy: shape.y});
620 }else{
621 matrix = m.normalize({dx: shape.x, dy: shape.y});
622 }
623 if(matrix.xy == 0 && matrix.yx == 0 && matrix.xx > 0 && matrix.yy > 0){
624 // special case to avoid filters
625 s.filter = "";
626 s.width = Math.floor(matrix.xx * shape.width);
627 s.height = Math.floor(matrix.yy * shape.height);
628 s.left = Math.floor(matrix.dx);
629 s.top = Math.floor(matrix.dy);
630 }else{
631 var ps = rawNode.parentNode.style;
632 s.left = "0px";
633 s.top = "0px";
634 s.width = ps.width;
635 s.height = ps.height;
636 matrix = m.multiply(matrix,
637 {xx: shape.width / parseInt(s.width), yy: shape.height / parseInt(s.height)});
638 var f = rawNode.filters["DXImageTransform.Microsoft.Matrix"];
639 if(f){
640 f.M11 = matrix.xx;
641 f.M12 = matrix.xy;
642 f.M21 = matrix.yx;
643 f.M22 = matrix.yy;
644 f.Dx = matrix.dx;
645 f.Dy = matrix.dy;
646 }else{
647 s.filter = "progid:DXImageTransform.Microsoft.Matrix(M11=" + matrix.xx +
648 ", M12=" + matrix.xy + ", M21=" + matrix.yx + ", M22=" + matrix.yy +
649 ", Dx=" + matrix.dx + ", Dy=" + matrix.dy + ")";
650 }
651 }
652 return this; // self
653 },
654 _setDimensions: function(width, height){
655 // summary:
656 // sets the width and height of the rawNode,
657 // if the surface size has been changed
658 // width: String
659 // width in pixels
660 // height: String
661 // height in pixels
662
663 var r = this.rawNode, f = r.filters["DXImageTransform.Microsoft.Matrix"];
664 if(f){
665 var s = r.style;
666 s.width = width;
667 s.height = height;
668 return this._applyTransform(); // self
669 }
670 return this; // self
671 }
672 });
673 vml.Image.nodeType = "rect";
674
675 vml.Text = declare("dojox.gfx.vml.Text", [vml.Shape, gs.Text], {
676 // summary:
677 // an anchored text (VML)
678 constructor: function(rawNode){
679 if(rawNode){rawNode.setAttribute("dojoGfxType", "text");}
680 this.fontStyle = null;
681 },
682 _alignment: {start: "left", middle: "center", end: "right"},
683 setShape: function(newShape){
684 // summary:
685 // sets a text shape object (VML)
686 // newShape: Object
687 // a text shape object
688 this.shape = g.makeParameters(this.shape, newShape);
689 this.bbox = null;
690 var r = this.rawNode, s = this.shape, x = s.x, y = s.y.toFixed(), path;
691 switch(s.align){
692 case "middle":
693 x -= 5;
694 break;
695 case "end":
696 x -= 10;
697 break;
698 }
699 path = "m" + x.toFixed() + "," + y + "l" + (x + 10).toFixed() + "," + y + "e";
700 // find path and text path
701 var p = null, t = null, c = r.childNodes;
702 for(var i = 0; i < c.length; ++i){
703 var tag = c[i].tagName;
704 if(tag == "path"){
705 p = c[i];
706 if(t) break;
707 }else if(tag == "textpath"){
708 t = c[i];
709 if(p) break;
710 }
711 }
712 if(!p){
713 p = r.ownerDocument.createElement("v:path");
714 r.appendChild(p);
715 }
716 if(!t){
717 t = r.ownerDocument.createElement("v:textpath");
718 r.appendChild(t);
719 }
720 p.v = path;
721 p.textPathOk = true;
722 t.on = true;
723 var a = vml.text_alignment[s.align];
724 t.style["v-text-align"] = a ? a : "left";
725 t.style["text-decoration"] = s.decoration;
726 t.style["v-rotate-letters"] = s.rotated;
727 t.style["v-text-kern"] = s.kerning;
728 t.string = s.text;
729 return this.setTransform(this.matrix); // self
730 },
731 _setFont: function(){
732 // summary:
733 // sets a font object (VML)
734 var f = this.fontStyle, c = this.rawNode.childNodes;
735 for(var i = 0; i < c.length; ++i){
736 if(c[i].tagName == "textpath"){
737 c[i].style.font = g.makeFontString(f);
738 break;
739 }
740 }
741 this.setTransform(this.matrix);
742 },
743 _getRealMatrix: function(){
744 // summary:
745 // returns the cumulative ("real") transformation matrix
746 // by combining the shape's matrix with its parent's matrix;
747 // it makes a correction for a font size
748 var matrix = this.inherited(arguments);
749 // It appears that text is always aligned vertically at a middle of x-height (???).
750 // It is impossible to obtain these metrics from VML => I try to approximate it with
751 // more-or-less util value of 0.7 * FontSize, which is typical for European fonts.
752 if(matrix){
753 matrix = m.multiply(matrix,
754 {dy: -g.normalizedLength(this.fontStyle ? this.fontStyle.size : "10pt") * 0.35});
755 }
756 return matrix; // dojox/gfx/matrix.Matrix2D
757 },
758 getTextWidth: function(){
759 // summary:
760 // get the text width, in px
761 var rawNode = this.rawNode, _display = rawNode.style.display;
762 rawNode.style.display = "inline";
763 var _width = g.pt2px(parseFloat(rawNode.currentStyle.width));
764 rawNode.style.display = _display;
765 return _width;
766 }
767 });
768 vml.Text.nodeType = "shape";
769
770 vml.Path = declare("dojox.gfx.vml.Path", [vml.Shape, pathLib.Path], {
771 // summary:
772 // a path shape (VML)
773 constructor: function(rawNode){
774 if(rawNode && !rawNode.getAttribute("dojoGfxType")){
775 rawNode.setAttribute("dojoGfxType", "path");
776 }
777 this.vmlPath = "";
778 this.lastControl = {};
779 },
780 _updateWithSegment: function(segment){
781 // summary:
782 // updates the bounding box of path with new segment
783 // segment: Object
784 // a segment
785 var last = lang.clone(this.last);
786 this.inherited(arguments);
787 if(arguments.length > 1){ return; } // skip transfomed bbox calculations
788 // add a VML path segment
789 var path = this[this.renderers[segment.action]](segment, last);
790 if(typeof this.vmlPath == "string"){
791 this.vmlPath += path.join("");
792 this.rawNode.path.v = this.vmlPath + " r0,0 e";
793 }else{
794 Array.prototype.push.apply(this.vmlPath, path); //FIXME: why not push()?
795 }
796 },
797 setShape: function(newShape){
798 // summary:
799 // forms a path using a shape (VML)
800 // newShape: Object
801 // a VML path string or a path object (see dojox/gfx.defaultPath)
802 this.vmlPath = [];
803 this.lastControl.type = ""; // no prior control point
804 this.inherited(arguments);
805 this.vmlPath = this.vmlPath.join("");
806 this.rawNode.path.v = this.vmlPath + " r0,0 e";
807 return this;
808 },
809 _pathVmlToSvgMap: {m: "M", l: "L", t: "m", r: "l", c: "C", v: "c", qb: "Q", x: "z", e: ""},
810 // VML-specific segment renderers
811 renderers: {
812 M: "_moveToA", m: "_moveToR",
813 L: "_lineToA", l: "_lineToR",
814 H: "_hLineToA", h: "_hLineToR",
815 V: "_vLineToA", v: "_vLineToR",
816 C: "_curveToA", c: "_curveToR",
817 S: "_smoothCurveToA", s: "_smoothCurveToR",
818 Q: "_qCurveToA", q: "_qCurveToR",
819 T: "_qSmoothCurveToA", t: "_qSmoothCurveToR",
820 A: "_arcTo", a: "_arcTo",
821 Z: "_closePath", z: "_closePath"
822 },
823 _addArgs: function(path, segment, from, upto){
824 var n = segment instanceof Array ? segment : segment.args;
825 for(var i = from; i < upto; ++i){
826 path.push(" ", n[i].toFixed());
827 }
828 },
829 _adjustRelCrd: function(last, segment, step){
830 var n = segment instanceof Array ? segment : segment.args, l = n.length,
831 result = new Array(l), i = 0, x = last.x, y = last.y;
832 if(typeof x != "number"){
833 // there is no last coordinate =>
834 // treat the first pair as an absolute coordinate
835 result[0] = x = n[0];
836 result[1] = y = n[1];
837 i = 2;
838 }
839 if(typeof step == "number" && step != 2){
840 var j = step;
841 while(j <= l){
842 for(; i < j; i += 2){
843 result[i] = x + n[i];
844 result[i + 1] = y + n[i + 1];
845 }
846 x = result[j - 2];
847 y = result[j - 1];
848 j += step;
849 }
850 }else{
851 for(; i < l; i += 2){
852 result[i] = (x += n[i]);
853 result[i + 1] = (y += n[i + 1]);
854 }
855 }
856 return result;
857 },
858 _adjustRelPos: function(last, segment){
859 var n = segment instanceof Array ? segment : segment.args, l = n.length,
860 result = new Array(l);
861 for(var i = 0; i < l; ++i){
862 result[i] = (last += n[i]);
863 }
864 return result;
865 },
866 _moveToA: function(segment){
867 var p = [" m"], n = segment instanceof Array ? segment : segment.args, l = n.length;
868 this._addArgs(p, n, 0, 2);
869 if(l > 2){
870 p.push(" l");
871 this._addArgs(p, n, 2, l);
872 }
873 this.lastControl.type = ""; // no control point after this primitive
874 return p;
875 },
876 _moveToR: function(segment, last){
877 return this._moveToA(this._adjustRelCrd(last, segment));
878 },
879 _lineToA: function(segment){
880 var p = [" l"], n = segment instanceof Array ? segment : segment.args;
881 this._addArgs(p, n, 0, n.length);
882 this.lastControl.type = ""; // no control point after this primitive
883 return p;
884 },
885 _lineToR: function(segment, last){
886 return this._lineToA(this._adjustRelCrd(last, segment));
887 },
888 _hLineToA: function(segment, last){
889 var p = [" l"], y = " " + last.y.toFixed(),
890 n = segment instanceof Array ? segment : segment.args, l = n.length;
891 for(var i = 0; i < l; ++i){
892 p.push(" ", n[i].toFixed(), y);
893 }
894 this.lastControl.type = ""; // no control point after this primitive
895 return p;
896 },
897 _hLineToR: function(segment, last){
898 return this._hLineToA(this._adjustRelPos(last.x, segment), last);
899 },
900 _vLineToA: function(segment, last){
901 var p = [" l"], x = " " + last.x.toFixed(),
902 n = segment instanceof Array ? segment : segment.args, l = n.length;
903 for(var i = 0; i < l; ++i){
904 p.push(x, " ", n[i].toFixed());
905 }
906 this.lastControl.type = ""; // no control point after this primitive
907 return p;
908 },
909 _vLineToR: function(segment, last){
910 return this._vLineToA(this._adjustRelPos(last.y, segment), last);
911 },
912 _curveToA: function(segment){
913 var p = [], n = segment instanceof Array ? segment : segment.args, l = n.length,
914 lc = this.lastControl;
915 for(var i = 0; i < l; i += 6){
916 p.push(" c");
917 this._addArgs(p, n, i, i + 6);
918 }
919 lc.x = n[l - 4];
920 lc.y = n[l - 3];
921 lc.type = "C";
922 return p;
923 },
924 _curveToR: function(segment, last){
925 return this._curveToA(this._adjustRelCrd(last, segment, 6));
926 },
927 _smoothCurveToA: function(segment, last){
928 var p = [], n = segment instanceof Array ? segment : segment.args, l = n.length,
929 lc = this.lastControl, i = 0;
930 if(lc.type != "C"){
931 p.push(" c");
932 this._addArgs(p, [last.x, last.y], 0, 2);
933 this._addArgs(p, n, 0, 4);
934 lc.x = n[0];
935 lc.y = n[1];
936 lc.type = "C";
937 i = 4;
938 }
939 for(; i < l; i += 4){
940 p.push(" c");
941 this._addArgs(p, [
942 2 * last.x - lc.x,
943 2 * last.y - lc.y
944 ], 0, 2);
945 this._addArgs(p, n, i, i + 4);
946 lc.x = n[i];
947 lc.y = n[i + 1];
948 }
949 return p;
950 },
951 _smoothCurveToR: function(segment, last){
952 return this._smoothCurveToA(this._adjustRelCrd(last, segment, 4), last);
953 },
954 _qCurveToA: function(segment){
955 var p = [], n = segment instanceof Array ? segment : segment.args, l = n.length,
956 lc = this.lastControl;
957 for(var i = 0; i < l; i += 4){
958 p.push(" qb");
959 this._addArgs(p, n, i, i + 4);
960 }
961 lc.x = n[l - 4];
962 lc.y = n[l - 3];
963 lc.type = "Q";
964 return p;
965 },
966 _qCurveToR: function(segment, last){
967 return this._qCurveToA(this._adjustRelCrd(last, segment, 4));
968 },
969 _qSmoothCurveToA: function(segment, last){
970 var p = [], n = segment instanceof Array ? segment : segment.args, l = n.length,
971 lc = this.lastControl, i = 0;
972 if(lc.type != "Q"){
973 p.push(" qb");
974 this._addArgs(p, [
975 lc.x = last.x,
976 lc.y = last.y
977 ], 0, 2);
978 lc.type = "Q";
979 this._addArgs(p, n, 0, 2);
980 i = 2;
981 }
982 for(; i < l; i += 2){
983 p.push(" qb");
984 this._addArgs(p, [
985 lc.x = 2 * last.x - lc.x,
986 lc.y = 2 * last.y - lc.y
987 ], 0, 2);
988 this._addArgs(p, n, i, i + 2);
989 }
990 return p;
991 },
992 _qSmoothCurveToR: function(segment, last){
993 return this._qSmoothCurveToA(this._adjustRelCrd(last, segment, 2), last);
994 },
995 _arcTo: function(segment, last){
996 var p = [], n = segment.args, l = n.length, relative = segment.action == "a";
997 for(var i = 0; i < l; i += 7){
998 var x1 = n[i + 5], y1 = n[i + 6];
999 if(relative){
1000 x1 += last.x;
1001 y1 += last.y;
1002 }
1003 var result = arcLib.arcAsBezier(
1004 last, n[i], n[i + 1], n[i + 2],
1005 n[i + 3] ? 1 : 0, n[i + 4] ? 1 : 0,
1006 x1, y1
1007 );
1008 for(var j = 0; j < result.length; ++j){
1009 p.push(" c");
1010 var t = result[j];
1011 this._addArgs(p, t, 0, t.length);
1012 this._updateBBox(t[0], t[1]);
1013 this._updateBBox(t[2], t[3]);
1014 this._updateBBox(t[4], t[5]);
1015 }
1016 last.x = x1;
1017 last.y = y1;
1018 }
1019 this.lastControl.type = ""; // no control point after this primitive
1020 return p;
1021 },
1022 _closePath: function(){
1023 this.lastControl.type = ""; // no control point after this primitive
1024 return ["x"];
1025 },
1026 _getRealBBox: function(){
1027 // summary:
1028 // returns an array of four points or null
1029 // This is called by setFill, which actually creates the path, so we want to avoid
1030 // duping the path repeatedly in the shape by clearing the path before re-add.
1031 this._confirmSegmented();
1032 if(this.tbbox){
1033 return this.tbbox; // Array
1034 }
1035 if(typeof this.shape.path == "string"){
1036 this.shape.path = "";
1037 }
1038 return this.inherited(arguments);
1039 }
1040 });
1041 vml.Path.nodeType = "shape";
1042
1043 vml.TextPath = declare("dojox.gfx.vml.TextPath", [vml.Path, pathLib.TextPath], {
1044 // summary:
1045 // a textpath shape (VML)
1046 constructor: function(rawNode){
1047 if(rawNode){rawNode.setAttribute("dojoGfxType", "textpath");}
1048 this.fontStyle = null;
1049 if(!("text" in this)){
1050 this.text = lang.clone(g.defaultTextPath);
1051 }
1052 if(!("fontStyle" in this)){
1053 this.fontStyle = lang.clone(g.defaultFont);
1054 }
1055 },
1056 setText: function(newText){
1057 // summary:
1058 // sets a text to be drawn along the path
1059 this.text = g.makeParameters(this.text,
1060 typeof newText == "string" ? {text: newText} : newText);
1061 this._setText();
1062 return this; // self
1063 },
1064 setFont: function(newFont){
1065 // summary:
1066 // sets a font for text
1067 this.fontStyle = typeof newFont == "string" ?
1068 g.splitFontString(newFont) :
1069 g.makeParameters(g.defaultFont, newFont);
1070 this._setFont();
1071 return this; // self
1072 },
1073
1074 _setText: function(){
1075 // summary:
1076 // sets a text shape object (VML)
1077 this.bbox = null;
1078 var r = this.rawNode, s = this.text,
1079 // find path and text path
1080 p = null, t = null, c = r.childNodes;
1081 for(var i = 0; i < c.length; ++i){
1082 var tag = c[i].tagName;
1083 if(tag == "path"){
1084 p = c[i];
1085 if(t) break;
1086 }else if(tag == "textpath"){
1087 t = c[i];
1088 if(p) break;
1089 }
1090 }
1091 if(!p){
1092 p = this.rawNode.ownerDocument.createElement("v:path");
1093 r.appendChild(p);
1094 }
1095 if(!t){
1096 t = this.rawNode.ownerDocument.createElement("v:textpath");
1097 r.appendChild(t);
1098 }
1099 p.textPathOk = true;
1100 t.on = true;
1101 var a = vml.text_alignment[s.align];
1102 t.style["v-text-align"] = a ? a : "left";
1103 t.style["text-decoration"] = s.decoration;
1104 t.style["v-rotate-letters"] = s.rotated;
1105 t.style["v-text-kern"] = s.kerning;
1106 t.string = s.text;
1107 },
1108 _setFont: function(){
1109 // summary:
1110 // sets a font object (VML)
1111 var f = this.fontStyle, c = this.rawNode.childNodes;
1112 for(var i = 0; i < c.length; ++i){
1113 if(c[i].tagName == "textpath"){
1114 c[i].style.font = g.makeFontString(f);
1115 break;
1116 }
1117 }
1118 }
1119 });
1120 vml.TextPath.nodeType = "shape";
1121
1122 vml.Surface = declare("dojox.gfx.vml.Surface", gs.Surface, {
1123 // summary:
1124 // a surface object to be used for drawings (VML)
1125 constructor: function(){
1126 gs.Container._init.call(this);
1127 },
1128 destroy: function(){
1129 this.clear(true);
1130 this.inherited(arguments);
1131 },
1132 setDimensions: function(width, height){
1133 // summary:
1134 // sets the width and height of the rawNode
1135 // width: String
1136 // width of surface, e.g., "100px"
1137 // height: String
1138 // height of surface, e.g., "100px"
1139 this.width = g.normalizedLength(width); // in pixels
1140 this.height = g.normalizedLength(height); // in pixels
1141 if(!this.rawNode) return this;
1142 var cs = this.clipNode.style,
1143 r = this.rawNode, rs = r.style,
1144 bs = this.bgNode.style,
1145 ps = this._parent.style, i;
1146 ps.width = width;
1147 ps.height = height;
1148 cs.width = width;
1149 cs.height = height;
1150 cs.clip = "rect(0px " + width + "px " + height + "px 0px)";
1151 rs.width = width;
1152 rs.height = height;
1153 r.coordsize = width + " " + height;
1154 bs.width = width;
1155 bs.height = height;
1156 for(i = 0; i < this.children.length; ++i){
1157 this.children[i]._setDimensions(width, height);
1158 }
1159 return this; // self
1160 },
1161 getDimensions: function(){
1162 // summary:
1163 // returns an object with properties "width" and "height"
1164 var t = this.rawNode ? {
1165 width: g.normalizedLength(this.rawNode.style.width),
1166 height: g.normalizedLength(this.rawNode.style.height)} : null;
1167 if(t.width <= 0){ t.width = this.width; }
1168 if(t.height <= 0){ t.height = this.height; }
1169 return t; // Object
1170 }
1171 });
1172
1173 vml.createSurface = function(parentNode, width, height){
1174 // summary:
1175 // creates a surface (VML)
1176 // parentNode: Node
1177 // a parent node
1178 // width: String|Number
1179 // width of surface, e.g., "100px" or 100
1180 // height: String|NUmber
1181 // height of surface, e.g., "100px" or 100
1182 // returns:
1183 // newly created surface
1184
1185 if(!width && !height){
1186 var pos = domGeom.position(parentNode);
1187 width = width || pos.w;
1188 height = height || pos.h;
1189 }
1190 if(typeof width == "number"){
1191 width = width + "px";
1192 }
1193 if(typeof height == "number"){
1194 height = height + "px";
1195 }
1196
1197 var s = new vml.Surface(), p = dom.byId(parentNode),
1198 c = s.clipNode = p.ownerDocument.createElement("div"),
1199 r = s.rawNode = p.ownerDocument.createElement("v:group"),
1200 cs = c.style, rs = r.style;
1201
1202 if(has("ie") > 7){
1203 rs.display = "inline-block";
1204 }
1205
1206 s._parent = p;
1207 s._nodes.push(c); // other elements will be deleted as parts of "c"
1208
1209 p.style.width = width;
1210 p.style.height = height;
1211
1212 cs.position = "absolute";
1213 cs.width = width;
1214 cs.height = height;
1215 cs.clip = "rect(0px " + width + " " + height + " 0px)";
1216 rs.position = "absolute";
1217 rs.width = width;
1218 rs.height = height;
1219 r.coordsize = (width === "100%" ? width : parseFloat(width)) + " " +
1220 (height === "100%" ? height : parseFloat(height));
1221 r.coordorigin = "0 0";
1222
1223 // create a background rectangle, which is required to show all other shapes
1224 var b = s.bgNode = r.ownerDocument.createElement("v:rect"), bs = b.style;
1225 bs.left = bs.top = 0;
1226 bs.width = rs.width;
1227 bs.height = rs.height;
1228 b.filled = b.stroked = "f";
1229
1230 r.appendChild(b);
1231 c.appendChild(r);
1232 p.appendChild(c);
1233
1234 s.width = g.normalizedLength(width); // in pixels
1235 s.height = g.normalizedLength(height); // in pixels
1236
1237 return s; // dojox/gfx/shape.Surface
1238 };
1239
1240 // Extenders
1241
1242 // copied from dojox/gfx/utils
1243 function forEach(object, f, o){
1244 o = o || kernel.global;
1245 f.call(o, object);
1246 if(object instanceof g.Surface || object instanceof g.Group){
1247 arr.forEach(object.children, function(shape){
1248 forEach(shape, f, o);
1249 });
1250 }
1251 }
1252
1253 var addPatch9624 = function(shape){
1254 if(this != shape.getParent()){
1255 // cleanup from old parent
1256 var oldParent = shape.getParent();
1257 if(oldParent) { oldParent.remove(shape); }
1258 // then move the raw node
1259 this.rawNode.appendChild(shape.rawNode);
1260 C.add.apply(this, arguments);
1261 // reapply visual attributes (slow..)
1262 forEach(this, function(s){
1263 if (typeof(s.getFont) == 'function'){ // text shapes need to be completely refreshed
1264 s.setShape(s.getShape());
1265 s.setFont(s.getFont());
1266 }
1267 if (typeof(s.setFill) == 'function'){ // if setFill is available a setStroke should be safe to assume also
1268 s.setFill(s.getFill());
1269 s.setStroke(s.getStroke());
1270 }
1271 });
1272 }
1273 return this; // self
1274 };
1275
1276 var add15 = function(shape){
1277 if(this != shape.getParent()){
1278 this.rawNode.appendChild(shape.rawNode);
1279 if(!shape.getParent()){
1280 // reapply visual attributes
1281 shape.setFill(shape.getFill());
1282 shape.setStroke(shape.getStroke());
1283 }
1284 C.add.apply(this, arguments);
1285 }
1286 return this; // self
1287 };
1288
1289 var C = gs.Container, Container = {
1290 add: config.fixVmlAdd === true ? addPatch9624 : add15,
1291 remove: function(shape, silently){
1292 // summary:
1293 // remove a shape from a group/surface
1294 // shape: dojox/gfx/shape.Shape
1295 // a VML shape object
1296 // silently: Boolean?
1297 // if true, regenerate a picture
1298 if(this == shape.getParent()){
1299 if(this.rawNode == shape.rawNode.parentNode){
1300 this.rawNode.removeChild(shape.rawNode);
1301 }
1302 C.remove.apply(this, arguments);
1303 }
1304 return this; // self
1305 },
1306 clear: function(){
1307 // summary:
1308 // removes all shapes from a group/surface
1309 var r = this.rawNode;
1310 while(r.firstChild != r.lastChild){
1311 if(r.firstChild != this.bgNode){
1312 r.removeChild(r.firstChild);
1313 }
1314 if(r.lastChild != this.bgNode){
1315 r.removeChild(r.lastChild);
1316 }
1317 }
1318 return C.clear.apply(this, arguments);
1319 },
1320 getBoundingBox: C.getBoundingBox,
1321 _moveChildToFront: C._moveChildToFront,
1322 _moveChildToBack: C._moveChildToBack
1323 };
1324
1325 var Creator = {
1326 // summary:
1327 // VML shape creators
1328 createGroup: function(){
1329 // summary:
1330 // creates a VML group shape
1331 var node = this.createObject(vml.Group, null); // dojox/gfx.Group
1332 // create a background rectangle, which is required to show all other shapes
1333 var r = node.rawNode.ownerDocument.createElement("v:rect");
1334 r.style.left = r.style.top = 0;
1335 r.style.width = node.rawNode.style.width;
1336 r.style.height = node.rawNode.style.height;
1337 r.filled = r.stroked = "f";
1338 node.rawNode.appendChild(r);
1339 node.bgNode = r;
1340 return node; // dojox/gfx.Group
1341 },
1342 createImage: function(image){
1343 // summary:
1344 // creates a VML image shape
1345 // image: Object
1346 // an image object (see dojox/gfx.defaultImage)
1347 if(!this.rawNode) return null;
1348 var shape = new vml.Image(),
1349 doc = this.rawNode.ownerDocument,
1350 node = doc.createElement('v:rect');
1351 node.stroked = "f";
1352 node.style.width = this.rawNode.style.width;
1353 node.style.height = this.rawNode.style.height;
1354 var img = doc.createElement('v:imagedata');
1355 node.appendChild(img);
1356 shape.setRawNode(node);
1357 this.rawNode.appendChild(node);
1358 shape.setShape(image);
1359 this.add(shape);
1360 return shape; // dojox/gfx/shape.Image
1361 },
1362 createRect: function(rect){
1363 // summary:
1364 // creates a rectangle shape
1365 // rect: Object
1366 // a path object (see dojox/gfx.defaultRect)
1367 if(!this.rawNode) return null;
1368 var shape = new vml.Rect,
1369 node = this.rawNode.ownerDocument.createElement("v:roundrect");
1370 if(has("ie") > 7){
1371 node.style.display = "inline-block";
1372 }
1373 shape.setRawNode(node);
1374 this.rawNode.appendChild(node);
1375 shape.setShape(rect);
1376 this.add(shape);
1377 return shape; // dojox/gfx.Rect
1378 },
1379 createObject: function(shapeType, rawShape) {
1380 // summary:
1381 // creates an instance of the passed shapeType class
1382 // shapeType: Function
1383 // a class constructor to create an instance of
1384 // rawShape: Object
1385 // properties to be passed in to the classes "setShape" method
1386 // overrideSize: Boolean
1387 // set the size explicitly, if true
1388 if(!this.rawNode) return null;
1389 var shape = new shapeType(),
1390 node = this.rawNode.ownerDocument.createElement('v:' + shapeType.nodeType);
1391 shape.setRawNode(node);
1392 this.rawNode.appendChild(node);
1393 switch(shapeType){
1394 case vml.Group:
1395 case vml.Line:
1396 case vml.Polyline:
1397 case vml.Image:
1398 case vml.Text:
1399 case vml.Path:
1400 case vml.TextPath:
1401 this._overrideSize(node);
1402 }
1403 shape.setShape(rawShape);
1404 this.add(shape);
1405 return shape; // dojox/gfx/shape.Shape
1406 },
1407 _overrideSize: function(node){
1408 var s = this.rawNode.style, w = s.width, h = s.height;
1409 node.style.width = w;
1410 node.style.height = h;
1411 node.coordsize = parseInt(w) + " " + parseInt(h);
1412 }
1413 };
1414
1415 lang.extend(vml.Group, Container);
1416 lang.extend(vml.Group, gs.Creator);
1417 lang.extend(vml.Group, Creator);
1418
1419 lang.extend(vml.Surface, Container);
1420 lang.extend(vml.Surface, gs.Creator);
1421 lang.extend(vml.Surface, Creator);
1422
1423 // Mouse/Touch event
1424 vml.fixTarget = function(event, gfxElement){
1425 // summary:
1426 // Adds the gfxElement to event.gfxTarget if none exists. This new
1427 // property will carry the GFX element associated with this event.
1428 // event: Object
1429 // The current input event (MouseEvent or TouchEvent)
1430 // gfxElement: Object
1431 // The GFX target element
1432 if (!event.gfxTarget) {
1433 event.gfxTarget = event.target.__gfxObject__;
1434 }
1435 return true;
1436 };
1437
1438 return vml;
1439 });