字体旋转竖排,最近一直在网上找,大多是利用TLF等,太麻烦.终于被我找到了集成Sprit来解决这个问题,封装了一下,贴出来,备用:
集成Sprit的核心类
package { import flash.display.Sprite; import flash.text.engine.ElementFormat; 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; public class RoutaTextAs extends Sprite{//"MS Mincho" 一个字体 /** * 旋转字体 * @param text 待旋转的文档 * @param fontSize * @param fontType * @param rotate 旋转度 * @param theHeight 高 * @param theWidth 宽 * @param x * @param y * @param spaceBetween 字体空间 * */ public function RoutaTextAs(text:String="" , fontSize:int=15 , fontType:String="宋体" , rotate:String= TextRotation.ROTATE_90 , theHeight:int=60 , theWidth:int=60, x:int=0 , y:int=0 , spaceBetween:int=20):void { var format:ElementFormat = new ElementFormat(); format.fontSize = fontSize; format.fontDescription = new FontDescription(fontType); var textBlock:TextBlock = new TextBlock(); textBlock.content = new TextElement(text, format); textBlock.lineRotation = rotate;//方向 var linePosition:Number =x; var previousLine:TextLine = null; while (true) { var textLine:TextLine = textBlock.createTextLine(previousLine, theHeight); trace(this.width); if (textLine == null || this.width > theWidth) { break; } textLine.y = y; textLine.x = linePosition; linePosition -= spaceBetween; addChild(textLine); previousLine = textLine; } } } }
Spirt必须add在UIComponent里面,包装了一层,可以直接使用:
<?xml version="1.0" encoding="utf-8"?> <mx:UIComponent xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()"> <mx:Script> <![CDATA[ import flash.text.engine.TextRotation; import mx.events.FlexEvent; public var text:String = "";//要加入的字体 public var fontSize:int = 15 ; public var fontType:String ="宋体"; public var rotate:String = TextRotation.ROTATE_90;//旋转角度 public var spaceBetween:int = 18;//旋转角度 protected function init():void{ var tt:RoutaTextAs = new RoutaTextAs(text , fontSize , fontType , rotate , this.height , this.width ,this.x , this.y , spaceBetween); this.addChild(tt); } ]]> </mx:Script> </mx:UIComponent>
一些参数需要自己调整,下面是Application
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="application1_initializeHandler(event)"> <mx:Script> <![CDATA[ import flash.text.engine.TextRotation; import mx.core.UIComponent; import mx.events.FlexEvent; protected function application1_initializeHandler(event:FlexEvent):void{ var rr:RoutaText = new RoutaText(); rr.height = 60; rr.width = 150; rr.spaceBetween = 55; rr.text = "猩红的撒旦斯蒂芬桑德菲杰撒" + "地方速度快李凤江桑德菲杰思考了打飞机克里" + "斯丁积分卡螺丝刀积分卡螺丝" + "刀杰弗里斯大开间付款了三等奖分散度看了 飞"; ttt.addChild(rr); } ]]> </mx:Script> <mx:Box id="ttt" x="409" y="151" width="250"/> </mx:Application>
用吧!
RoutaTextAs 修改了一下.支持横排很竖排 package { import flash.display.Sprite; import flash.text.engine.ElementFormat; 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; public class RoutaTextAs extends Sprite{//"MS Mincho" 一个字体 /** * 旋转字体 * @param text 待旋转的文档 * @param fontSize * @param fontType * @param rotate 旋转度 * @param theHeight 高 * @param theWidth 宽 * @param x * @param y * @param spaceBetween 字体空间 * */ public function RoutaTextAs(text:String="" , fontSize:int=15 , fontType:String="宋体" , rotate:String= TextRotation.ROTATE_90 , theHeight:int=60 , theWidth:int=60, x:int=0 , y:int=0 , spaceBetween:int=20):void { var format:ElementFormat = new ElementFormat(); format.fontSize = fontSize; format.fontDescription = new FontDescription(fontType); var textBlock:TextBlock = new TextBlock(); textBlock.content = new TextElement(text, format); textBlock.lineRotation = rotate;//方向 var previousLine:TextLine = null; if(rotate == TextRotation.ROTATE_90){ var linePosition:Number = x; while (true) { var textLine:TextLine = textBlock.createTextLine(previousLine, theHeight); if (textLine == null || this.width > theWidth) { break; } textLine.y = y; textLine.x = linePosition; linePosition += spaceBetween; addChild(textLine); previousLine = textLine; } }else if(rotate == TextRotation.ROTATE_0){ var linePosition:Number = y + fontSize ; while (true) { var textLine:TextLine = textBlock.createTextLine(previousLine, theWidth); if (textLine == null ||( this.height+fontSize) >= theHeight) { break; } textLine.y = linePosition; textLine.x = x; linePosition += spaceBetween; addChild(textLine); previousLine = textLine; } } } } }
相关推荐
自定义textview 实现字体竖排效果
android利用Paint在Canvas上实现竖排写字
默认 MenuBar横排 此为竖排 源文件从网上下载 经楼主移植为mxlm,方便拖拽使用,附图标添加示例
css实现文字竖排效果
Flex3 排版为竖着的TabNavigator实例。
精彩编程与编程技巧-旋转字体 ...
Qt显示旋转文字的方式 显示基本方法 利用QPainter基本函数+rotate/translate绘制旋转图形的方法
使用python 2.7,初学,代码比较简单。 numPrinter.py 复制代码 代码如下: #!/usr/bin/env python # -*- coding: utf-8 -*- ”’ @Author:Quico Tomy @Function:Input a phone number and print by line ...
实现文字竖排 实现方法,传入一个字符串,代表横排文字。传入一个整型值代表折行的位置。返回一个字符串,输出该字符串则横排文字已被转换为竖排文字(从右向左)
1. 包里包含源码和一个测试用例,可直接看到效果。 2. 竖排文字的一些说明,移步以下链接 https://blog.csdn.net/piaoyun29/article/details/123255514
mfc自带的tabsheet控件是横排按钮在上面的,这个自绘控件实现在左侧竖排的Tab选择,并且可以添加图标。
C#语言实现的文字竖排工具程序源码.rar,对学习C#真的很有用的资源。
VB之文件处理精彩编程-字体的特殊效果:竖排、环绕(3KB)
HTML竖排菜单制作,美观的竖排菜单,制作竖排菜单时可能用得到
不用另外的子题库,将LineChart的文字进行竖排,很简单的例子
实现struts2标签chekboxlist竖排; 可以实现checkboslist横向放置个数(自行修改)
把viewpager+listview做成了一个工具类,方便调用。实现Page竖排显示并滑动。方便动态加载数据。
Label控件竖排显示文字一般都是横排的,接下来为大家分享个方法让它变成竖排,感兴趣的童鞋们可以学习下,希望对你有所帮助
HTML5实现图标会旋转的竖向导航菜单,竖直排列的网站导航,当鼠标悬停于图标时,图标会旋转,称之为旋转菜单也不为过。
在word、excel中可以轻松的实现文字竖排的形式,但是在html页面中呢?当然也可以实现,下面有个不错的示例,大家可以参考学习下