我正在尝试在 UITextField 中使用嵌入式字体(Flex 4.6)。只要我使用在 Windows 中注册的字体,它就可以正常工作,但是对于未注册的字体, UITextField 默认为 TimesRoman (或类似的东西)
请注意,当我检查字体是否嵌入时,它返回 True (FlexGlobals.topLevelApplication.systemManager.isFontFaceEmbedded(txtFormatCoda))
那么我错过了什么?
在下面的代码中,如果我将字体 Kredit 添加到 Windows 字体中,UI 文本字段将以 Kredit 字体显示,但如果我将其从 Windows/font 目录中删除,则该字段将显示为 TimesNewRoman(默认字体)。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="onComplete()">
<s:Group id="TextCanvas" x="121" y="97" width="474" height="800">
</s:Group>
<fx:Style>
@font-face {
src: url("fonts/KREDIT1.TTF");
fontFamily: Kredit;
embed-as-cff:false;
advancedAntiAliasing:true;
}
</fx:Style>
<fx:Script>
import mx.core.FlexGlobals;
import mx.core.UIComponent;
import mx.core.UITextField;
import mx.core.UITextFormat;
public function onComplete():void{
var txtFldCoda:UITextField = new UITextField();
var txtFormatCoda:UITextFormat = new UITextFormat(this.systemManager);
var compCoda:UIComponent = new UIComponent();
compCoda.addChild(txtFldCoda);
txtFldCoda.embedFonts=true;
txtFldCoda.width=300;
txtFormatCoda.size=33;
TextCanvas.addElement(compCoda);
txtFldCoda.text="Testing Kredit";
txtFormatCoda.font= "Kredit";
txtFormatCoda.color="0x0ff345";
var b2:Boolean = FlexGlobals.topLevelApplication.systemManager.isFontFaceEmbedded(txtFormatCoda);
if(b2==false){
trace("not embedded: " + txtFormatCoda.font);
}
txtFldCoda.defaultTextFormat= txtFormatCoda;//note that setTextFormat must be after setting the text
txtFldCoda.setTextFormat(txtFormatCoda);//note that setTextFormat must be after setting the text
txtFldCoda.x=0;
txtFldCoda.y=100;
}
</fx:Script>
</s:Application>