MapCSS in progress. Vast amounts still to do, but the meat of it is here. POIs are...
[potlatch2.git] / net / systemeD / halcyon / styleparser / TextStyle.as
1 package net.systemeD.halcyon.styleparser {
2
3         import flash.display.*;
4         import flash.text.TextField;
5         import flash.text.TextFormat;
6         import flash.filters.BitmapFilter;
7         import flash.filters.GlowFilter;
8
9         public class TextStyle extends Style {
10
11                 public var font_family:String;
12                 public var font_bold:Boolean;
13                 public var font_italic:Boolean;
14                 public var font_caps:Boolean;
15                 public var font_size:uint;
16                 public var text_color:uint;
17                 public var text_offset:Number;          // Y offset - i.e. within or outside casing?
18                 public var max_width:Number;            // maximum width of label
19                 public var text:String;
20                 public var text_halo_color:uint;
21                 public var text_halo_radius:uint=0;
22                 public var text_onpath:Boolean;         // true if on line
23
24                 override public function get properties():Array {
25                         return [
26                                 'font_family','font_bold','font_italic','font_caps','font_size',
27                                 'text_color','text_offset','max_width',
28                                 'text','text_halo_color','text_halo_radius','text_onpath'
29                         ];
30                 }
31
32                 
33                 public function getTextFormat():TextFormat {
34                         return new TextFormat(font_family ? font_family: "DejaVu",
35                                                                   font_size   ? font_size  : 8,
36                                                                   text_color  ? text_color : 0,
37                                                                   font_bold   ? font_bold  : false,
38                                                                   font_italic ? font_italic: false);
39                 }
40         
41                 public function getHaloFilter():Array {
42                         var filter:BitmapFilter=new GlowFilter(text_halo_color  ? text_halo_color  : 0xFFFFFF,1,
43                                                                                                    text_halo_radius ? text_halo_radius: 2,
44                                                                                                    text_halo_radius ? text_halo_radius: 2,255);
45                         return [filter];
46                 }
47                 
48                 public function writeNameLabel(d:DisplayObjectContainer,a:String,x:Number,y:Number):TextField {
49                         var tf:TextField = new TextField();
50                         var n:TextFormat = getTextFormat();
51                         n.align = "center";
52                         tf.embedFonts = true;
53                         tf.defaultTextFormat = n;
54                         tf.text = a;
55                         if (max_width) {
56                                 tf.width=max_width;
57                                 tf.wordWrap=true;
58                                 tf.height=tf.textHeight+4;
59                         } else {
60                                 tf.width = tf.textWidth+4;
61                                 tf.height = tf.textHeight+4;
62                         }
63                         if (text_halo_radius>0) { tf.filters=getHaloFilter(); }
64                         d.x=x-tf.width/2;
65                         d.y=y+(text_offset ? text_offset : 0);
66                         d.addChild(tf);
67                         return tf;
68                 }
69
70         }
71
72 }