Draw multiple strokes, label POIs, and much much more fun.
[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 {
10
11                 public var font_name:String;
12                 public var font_bold:Boolean;
13                 public var font_italic:Boolean;
14                 public var font_caps:Boolean;
15                 public var text_size:uint;
16                 public var text_colour:uint;
17                 public var text_offset:Number;  // Y offset - i.e. within or outside casing?
18                 public var text_width:Number;   // maximum width of label
19                 public var tag:String;
20                 public var pullout_colour:uint;
21                 public var pullout_radius:uint=0;
22                 public var isLine:Boolean;
23                 public var sublayer:uint=0;
24
25                 public function getTextFormat():TextFormat {
26                         return new TextFormat(font_name   ? font_name : "DejaVu",
27                                                                   text_size   ? text_size : 8,
28                                                                   text_colour ? text_colour: 0,
29                                                                   font_bold   ? font_bold : false,
30                                                                   font_italic ? font_italic: false);
31                 }
32         
33                 public function getPulloutFilter():Array {
34                         var filter:BitmapFilter=new GlowFilter(pullout_colour ? pullout_colour : 0xFFFFFF,1,
35                                                                                                    pullout_radius ? pullout_radius: 2,
36                                                                                                    pullout_radius ? pullout_radius: 2,255);
37                         return [filter];
38                 }
39                 
40                 public function writeNameLabel(d:DisplayObjectContainer,a:String,x:Number,y:Number):TextField {
41                         var tf:TextField = new TextField();
42                         var n:TextFormat = getTextFormat();
43                         n.align = "center";
44                         tf.embedFonts = true;
45                         tf.defaultTextFormat = n;
46                         tf.text = a;
47                         if (text_width) {
48                                 tf.width=text_width;
49                                 tf.wordWrap=true;
50                                 tf.height=tf.textHeight+4;
51                         } else {
52                                 tf.width = tf.textWidth+4;
53                                 tf.height = tf.textHeight+4;
54                         }
55                         if (pullout_radius>0) { tf.filters=getPulloutFilter(); }
56                         d.x=x-tf.width/2;
57                         d.y=y+(text_offset ? text_offset : 0);
58                         d.addChild(tf);
59                         return tf;
60                 }
61
62         }
63
64 }