在纯AS工程中嵌入个别字体方法 (转载)
2010-09-25 18:36
330 查看
在纯AS工程中嵌入个别字体方法
2009-11-26 10:00前两天接到主管任务,让研究在纯AS工程中嵌入个别字体。在网上找了一大通,也只找到了在Flex项目中使用CSS也嵌入个别字体的方法。最后很无奈的发现网上好像没有我想找的资料。就在此时让我有个想法,在CSS中控制嵌入字体使用的是unicodeRange属性,那我能不能在Embed标签中也使用它呢?实验发现,Embed标签中是可以使用unicodeRange属性的。下面说说我在纯AS工程中是怎么嵌入个别字体的。 工程开始之前先告诉大家,我要嵌入的字符是"空山无人,水流花开。",要使用的字体是楷体字; 1.打包要嵌入字体到一个Swf文件中 (1).新建一个纯AS工程,内容如下: |
整个工程如下: package { import flash.display.Loader; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageQuality; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.ProgressEvent; import flash.net.URLRequest; import flash.system.LoaderContext; import flash.text.Font; import flash.text.TextField; import flash.text.TextFormat; import flash.utils.getDefinitionByName; public class FontTest extends Sprite { private var txt:TextField; private var fontLoader:Loader; public function FontTest():void { if(stage!=null){ init(); }else{ addEventListener(Event.ADDED_TO_STAGE,init); } } private function init():void{ stage.quality = StageQuality.HIGH; stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; stage.showDefaultContextMenu = false; txt = new TextField(); txt.x = stage.stageWidth/3; txt.y = stage.stageHeight/2; txt.width = 500; txt.height = 30; addChild(txt); fontLoader = new Loader(); fontLoader.load(new URLRequest("LoadFont.swf"), new LoaderContext(false, loaderInfo.applicationDomain)); fontLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler); fontLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler); } private function progressHandler(e:ProgressEvent):void { var ratio:int = e.bytesLoaded / e.bytesTotal * 100; txt.text = "loading... " + ratio + "%"; } private function completeHandler(e:Event):void { fontLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandler); fontLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandler); var MyFont:Class = getDefinitionByName("LoadFont_RoundHand") as Class; // 注册全局字体 Font.registerFont(MyFont); var myFont:Font = new MyFont() as Font; // 应用字体 var format:TextFormat = new TextFormat(myFont.fontName, 25, null, true); txt.defaultTextFormat = format; // 嵌入字体 txt.embedFonts = true; txt.text = "空山无人,水流花开。"; } } }
相关文章推荐
- 在纯AS工程中嵌入个别字体方法
- Matlab,Visio等生成的图片的字体嵌入问题解决方法
- Flash字体嵌入方法总结—(4)进阶篇
- 【转】PDF文件【由Latex、CTex或MS Word等生成】嵌入所有字体的快速解决方法
- [Flex] FlashBuilder 4.6运用标签嵌入字体方法
- js 将json字符串转换为json对象的方法解析 作者: 字体:[增加 减小] 类型:转载 将json字符串转换为json对象的方法。在数据传输过程中,json是以文本,即字符串的形式传递的,而J
- python在不同层级目录import模块的方法 作者:运维之路 字体:[增加 减小] 类型:转载 时间:2016-01-31 我要评论 这篇文章主要介绍了python 在不同层级目录import
- 使用 Cufon 渲染网页字体(转载自ibm developerwork,在网页里引入特殊字体的方法,通过js实现字体渲染)(1)
- Flex嵌入字体的方法(一)
- <转载>SpringMVC(7): 对Class.getResourceAsStream和ClassLoader.getResourceAsStream方法所使用的资源路径的解释
- Flex嵌入字体的方法(二)
- flash 嵌入字体方法
- linux字体发虚的解决方法【转载】
- iOS工程调试小技巧一:交换dealloc、字体方法,重写description
- Matlab,Visio等生成的图片的字体嵌入问题解决方法
- PPT嵌入字体的方法
- 修改iar工程,字体变化的解决方法
- PDF文件【由Latex、CTex或MS Word等生成】嵌入所有字体的快速解决方法
- Flash Builder 嵌入字体方法总结
- EDAS字体嵌入问题解决方法