在SWF使用AS3嵌入字体

编程入门 行业动态 更新时间:2024-10-19 05:27:08
本文介绍了在SWF使用AS3嵌入字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在使用闪光灯(和AIR为Android和iOS的eventuall)的翻译一些短语的项目。虽然大多数字体都很好也有一些,我要加载用户选择了语言之后。在一年前,我产生了几个SWF文件(孟加拉语和乌尔都语),并把它们放在我的Web服务器上。 Flash应用程序,然后在需要时加载它们,一切都OK了...   然而,因为我即将实现,我想我应该生成SWF文件的其他语言是在管道中,由于某种原因,我不能管理它的工程!不用说,我已经放错位置(整理)原AS3源两种字体我已经做了。

I have a project using flash (and AIR for android and eventuall iOS) for translating some phrases. Although most fonts are fine there are some that I have to load after the user has chosen the languages. Over a year ago I generated a couple of swf files (Bengali and Urdu) and put them on my web server. The flash application then loads them when required and everything is OK... However as I am nearing implementing the project I thought I should generate the swf files for the other languages that are in the pipeline and for some reason I can't manage it! Needless to say I have misplaced (tidied) the original AS3 source for the two fonts I have done.

package { import flash.display.Sprite; import flash.events.Event; public class ArabicF extends Sprite { [Embed(source = "trado.ttf", fontName = "ArabicX", fontFamily = "ArabicY", fontWeight = "normal", fontStyle = "normal", mimeType = "application/x-font", advancedAntiAliasing="true", embedAsCFF="true")] public static const ArabicZ:Class; } }

这已经从一个更简单的形式展开为我添加的东西得到它的工作,我必须尝试真假所有排列。我加载瑞士法郎确定,但随后无法提取的类。随着两种字体嵌入我以前瑞士法郎类和参数都具有相同的名字和他们的工作罚款(即     Urdu.swf 再后来:     VAR FontClass:类= evt.target.applicationDomain.getDefinition(乌尔都语)为类; 接着     Font.registerFont(FontClass.Urdu); 在上述Arabic.swf我尝试

This has expanded from a much simpler form as I added things to get it to work and I must have tried all permutations of true and false. I load the swf ok but then can't extract the class. With the two fonts I embedded before the swf class and the parameter all have the same name and they work fine (i.e. Urdu.swf then later: var FontClass:Class = evt.target.applicationDomain.getDefinition("Urdu") as Class; and then Font.registerFont(FontClass.Urdu); in the calling .as application with the above Arabic.swf I try

trace("1 Arabic "+evt.target.applicationDomain.hasDefinition("ArabicF")); trace("2 Arabic "+evt.target.applicationDomain.hasDefinition("Arabic")); trace("3 ArabicX "+evt.target.applicationDomain.hasDefinition("ArabicX")); trace("4 ArabicY "+evt.target.applicationDomain.hasDefinition("ArabicY")); trace("5 ArabicZ "+evt.target.applicationDomain.hasDefinition("ArabicZ"));

但都返回false

but all return false

PS也尝试过使用fontswf.bat这又似乎使所装载的非常相似的SWF文件生成Arabic.swf但我不能从中提取类

PS also tried generating the Arabic.swf using fontswf.bat which again seems to make a very similar swf file which is loaded but I can't extract the class from it

PPS我使用的是FlashDevelop和字体SWF被设置为AS3标准的项目编译器选项。

PPS I'm using flashdevelop and the font swf are set up as AS3 standard project compiler options.

推荐答案

我不使用Flash开发,但也许我可以提供从我实施一些观点。

I don't use Flash Develop, but perhaps I can offer some perspective from my implementation.

如果我想嵌入宋体,嵌入SWF将为ActionScript导出嵌入字体。在它的文档类,使用 registerFont() 如下:

If I wanted to embed Arial, the embedding swf would "Export for ActionScript" the embedded font. In its document class, use registerFont() as below:

Font.registerFont(Arial);

像其他SWF,您会使用一个的 装载机 将其导入到运行时,在这一点上,字体将提供给您的全局表。您可以查询注册的字体的完整列表,使用 enumerateFonts()。

var fontList:Array = Font.enumerateFonts(); for (var i:int = 0; i < fontList.length; i++) { trace(fontList[i].fontName); }

假设我们已经有了一个名为TXT文本字段,你就可以实现该字体用的 调用setTextFormat() 像这样:

Assuming we've got a TextField called "txt", you can then implement that font with setTextFormat() like so:

var format:TextFormat = new TextFormat(); format.font = "Arial"; txt.embedFonts = true; txt.antiAliasType = AntiAliasType.ADVANCED; txt.setTextFormat(format); txt.defaultTextFormat = format;

从Adobe在使用这些的最后两个设置:

当你使用应用TextFormat对象的文本字段   TextField.defaultTextFormat属性或TextField.setTextFormat()   方法,只是它定义的属性被应用。使用   TextField.defaultTextFormat属性来应用格式之前,您   添加文本到文本字段,以及setTextFormat()方法来添加   格式化后添加文本到文本字段。

"When you apply a TextFormat object to a text field using the TextField.defaultTextFormat property or the TextField.setTextFormat() method, only its defined properties are applied. Use the TextField.defaultTextFormat property to apply formatting BEFORE you add text to the TextField, and the setTextFormat() method to add formatting AFTER you add text to the TextField."

正如我以前说过,我的工作流程不使用闪光灯开发,而是闪存IDE嵌入字体到主权财富基金。您的结果可能会有所不同,但要注意必须设置的embedFonts 为true,否则不会到你的嵌入字体回应。我之前已经失去了头发的问题。

As I said before, my workflow doesn't utilize Flash Develop, but rather Flash IDE to embed the fonts into the swfs. Your results may vary, but be aware you must set embedFonts to true, or it won't respond to your embedded font. I've lost hair on that issue before.

希望有所帮助。欢呼声中,

Hope that helps. Cheers,

更多推荐

在SWF使用AS3嵌入字体

本文发布于:2023-11-23 16:02:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622059.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字体   SWF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!