root / trunk / web / dojo / dojox / drawing / stencil / Text.js @ 10
History | View | Annotate | Download (2.74 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.drawing.stencil.Text"]){ |
||
9 | dojo._hasResource["dojox.drawing.stencil.Text"]=true; |
||
10 | dojo.provide("dojox.drawing.stencil.Text");
|
||
11 | dojox.drawing.stencil.Text=dojox.drawing.util.oo.declare(dojox.drawing.stencil._Base,function(_1){
|
||
12 | },{type:"dojox.drawing.stencil.Text",anchorType:"none",baseRender:true,align:"start",valign:"top",_lineHeight:1,typesetter:function(_2){ |
||
13 | if(dojox.drawing.stencil.Text.typeset){
|
||
14 | this._rawText=_2;
|
||
15 | return dojox.drawing.stencil.Text.typeset(_2);
|
||
16 | } |
||
17 | return _2;
|
||
18 | },setText:function(_3){ |
||
19 | if(this.enabled){ |
||
20 | _3=this.typesetter(_3);
|
||
21 | } |
||
22 | this._text=_3;
|
||
23 | this._textArray=[];
|
||
24 | this.created&&this.render(_3); |
||
25 | },getText:function(){ |
||
26 | return this._rawText||this._text; |
||
27 | },dataToPoints:function(o){ |
||
28 | o=o||this.data;
|
||
29 | var w=o.width=="auto"?1:o.width; |
||
30 | var h=o.height||this._lineHeight; |
||
31 | this.points=[{x:o.x,y:o.y},{x:o.x+w,y:o.y},{x:o.x+w,y:o.y+h},{x:o.x,y:o.y+h}]; |
||
32 | return this.points; |
||
33 | },pointsToData:function(p){ |
||
34 | p=p||this.points;
|
||
35 | var s=p[0]; |
||
36 | var e=p[2]; |
||
37 | this.data={x:s.x,y:s.y,width:e.x-s.x,height:e.y-s.y}; |
||
38 | return this.data; |
||
39 | },render:function(_4){ |
||
40 | this.remove(this.shape,this.hit); |
||
41 | !this.annotation&&this.renderHit&&this._renderOutline(); |
||
42 | if(_4){
|
||
43 | this._text=_4;
|
||
44 | this._textArray=this._text.split("\n"); |
||
45 | } |
||
46 | var d=this.pointsToData(); |
||
47 | var h=this._lineHeight; |
||
48 | var x=d.x+this.style.text.pad*2; |
||
49 | var y=d.y+this._lineHeight-(this.textSize*0.4); |
||
50 | if(this.valign=="middle"){ |
||
51 | y-=h/2;
|
||
52 | } |
||
53 | this.shape=this.container.createGroup(); |
||
54 | dojo.forEach(this._textArray,function(_5,i){ |
||
55 | var tb=this.shape.createText({x:x,y:y+(h*i),text:unescape(_5),align:this.align}).setFont(this.style.currentText).setFill(this.style.currentText.color); |
||
56 | this._setNodeAtts(tb);
|
||
57 | },this);
|
||
58 | this._setNodeAtts(this.shape); |
||
59 | },_renderOutline:function(){ |
||
60 | if(this.annotation){ |
||
61 | return;
|
||
62 | } |
||
63 | var d=this.pointsToData(); |
||
64 | if(this.align=="middle"){ |
||
65 | d.x-=d.width/2-this.style.text.pad*2; |
||
66 | }else{
|
||
67 | if(this.align=="start"){ |
||
68 | d.x+=this.style.text.pad;
|
||
69 | }else{
|
||
70 | if(this.align=="end"){ |
||
71 | d.x-=d.width-this.style.text.pad*3; |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | if(this.valign=="middle"){ |
||
76 | d.y-=(this._lineHeight)/2-this.style.text.pad; |
||
77 | } |
||
78 | this.hit=this.container.createRect(d).setStroke(this.style.currentHit).setFill(this.style.currentHit.fill); |
||
79 | this._setNodeAtts(this.hit); |
||
80 | this.hit.moveToBack();
|
||
81 | },makeFit:function(_6,w){ |
||
82 | var _7=dojo.create("span",{innerHTML:_6,id:"foo"},document.body); |
||
83 | var sz=1; |
||
84 | dojo.style(_7,"fontSize",sz+"px"); |
||
85 | var _8=30; |
||
86 | while(dojo.marginBox(_7).w<w){
|
||
87 | sz++; |
||
88 | dojo.style(_7,"fontSize",sz+"px"); |
||
89 | if(_8--<=0){ |
||
90 | break;
|
||
91 | } |
||
92 | } |
||
93 | sz--; |
||
94 | var _9=dojo.marginBox(_7);
|
||
95 | dojo.destroy(_7); |
||
96 | return {size:sz,box:_9}; |
||
97 | }}); |
||
98 | dojox.drawing.register({name:"dojox.drawing.stencil.Text"},"stencil"); |
||
99 | } |