在as3.0中有 FTE可針對文字去測量其寬度、高度等
針對個別的文字去做處理
相關官網的說明可見此
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS6C0BB8ED-2805-467a-9C71-F9D757F33FB6.html
ElementFormat是定義文字的相關屬性(字型、大小、顏色等等)
然後再new一個TextElement設定文字格式和文字內容
再將其放到一個TextBlock裡面
TextBlock裡面則有許多相關的操作函數
可以對個別的文字做旋轉、定位等等
http://livedocs.adobe.com/flex/3_cn/langref/flash/text/engine/TextBlock.html
詳細的手冊說明在上面
裡面的lineRotation將角度設為九十度(TextRotation.ROTATE_90)時
文字就會呈現傳統的中文直式書寫方式呈現
下面的是將文字改為直式文字的範例程式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
package { import flash.display.Sprite; import flash.text.engine.FontDescription; import flash.text.engine.TextBlock; import flash.text.engine.TextElement; import flash.text.engine.TextLine; import flash.text.engine.TextRotation; import flash.text.engine.ElementFormat; public class TextBlock_lineRotationExample extends Sprite { public function TextBlock_lineRotationExample():void { var s:String = "一向批判電影不會「口下留情」的大陸媒體,竟在李安導演《少年PI的奇幻漂流》內地上映後,於中國最大入口網站搜狐,罕見大讚道:『影片美輪美奐的視覺奇觀,身臨其境的3D效果。』"; var fontDescription:FontDescription = new FontDescription("MS Mincho"); var format:ElementFormat = new ElementFormat(); format.fontSize = 15; format.fontDescription = fontDescription; var textElement:TextElement = new TextElement(s, format); var textBlock:TextBlock = new TextBlock(); textBlock.content = textElement; textBlock.lineRotation = TextRotation.ROTATE_90; var linePosition:Number = this.stage.stageWidth - 120; var previousLine:TextLine = null; while (true) { var textLine:TextLine = textBlock.createTextLine( previousLine, 300); if (textLine == null) break; textLine.y = 30; textLine.x = linePosition; linePosition -= 24; addChild(textLine); previousLine = textLine; } } } } |