9.17.嵌入字体

问题
我要嵌入自己的字体
解决办法
通过[Embed] 元数据嵌入字体,设置文本框的embedFonts 属性为true,通过<font> 标签,TextFormat 对象或CSS应用字体
讨论
当用户电脑上没有相应字体时可以通过[Embed]元数据把字体嵌入到swf中,[Embed] 元数据在类外面申明,可以嵌入TrueType 字体或系统字体,语法如下:
+展开
-ActionScript
[Embed(source="pathToTtfFile", fontName="FontName", mimeType="application/x-font-truetype")]

TrueType f字体路径可以是相对或绝对路径,比如:
+展开
-ActionScript
[Embed(source="C:\Windows\Fonts\Example.ttf",fontName="ExampleFont",mimeType="application/x-font-truetype")]

fontName 属性可被CSS或ActionScript引用。
嵌入系统字体语法类似,只是systemFont 属性代替了source 属性。systemFont 属性指定嵌入的系统字体,下面的例子嵌入Times New Roman字体:
+展开
-ActionScript
[Embed(systemFont="Times New Roman",fontName="Times New Roman",mimeType="application/x-font-truetype")]

嵌入好字体后,下一步就是告诉文本框使用嵌入的字体,可设置embedFonts 属性为true:
+展开
-ActionScript
field.embedFonts = true;

接下来通过<font> 标签,TextFormat 对象或CSS使用之。例如,如果fontName 值为Times New Roman:
+展开
-ActionScript
formatter.font = "Times New Roman";

使用<font>标签:
+展开
-ActionScript
field.htmlText = "<font family='Times New Roman'>Example</font>";

使用CSS:
+展开
-ActionScript
var css:StyleSheet = new StyleSheet( );
css.setStyle("p", {fontFamily: "Times New Roman"});
field.htmlText = "<p>Example</p>";

加支付宝好友偷能量挖...


评论(0)网络
阅读(77)喜欢(0)flash/flex/fcs/AIR