嵌入的字体不适用于TextField

嵌入的字体不适用于TextField

本文介绍了Flex 4.6:嵌入的字体不适用于TextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在UITextField中使用嵌入字体(Flex 4.6)。只要我使用在Windows注册的字体,它可以正常工作,但是对于没有注册的字体,UITextField默认为TimesRoman(或者类似的东西)



注意当我检查字体是否嵌入,它返回True(FlexGlobals.topLevelApplication.systemManager.isFontFaceEmbedded(txtFormatCoda))

那么我错过了什么?在下面的代码中,如果将字体Kredit添加到Windows字体中,UI文本字段将显示为Kredit字体,但是如果从Windows / font目录中将其删除,
$ b

 <?xml version =1.0encoding =utf-8字段出现在TimesNewRoman(默认字体) ?> 
xmlns:s =library://ns.adobe.com/flex/spark
xmlns:mx =library://ns.adobe.com/flex/mxminWidth =955minHeight =600creationComplete =onComplete()>
< / s:Group>
< fx:Style>
@ font-face {
src:url(fonts / KREDIT1.TTF);
fontFamily:Kredit;
embed-as-cff:false;
advancedAntiAliasing:true;
}
< / fx:样式>
< fx:Script>
导入mx.core.FlexGlobals;
导入mx.core.UIComponent;
导入mx.core.UITextField;
导入mx.core.UITextFormat;

$ b 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 =测试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; //注意setTextFormat必须在设置文本
之后txtFldCoda.setTextFormat(txtFormatCoda); //注意setTextFormat必须在设置文本
txtFldCoda.x = 0;
txtFldCoda.y = 100;
}
< / fx:Script>
< / s:Application>


解决方案

感谢Mahesh



实际上,这对我有用:

  var comp:UIComponent = new UIComponent(); 
comp.setStyle('fontFamily',fontName);

基本上,我必须在UITextField的父类UIComponent上做setStyle。我希望Adobe能够记录这一点。


I am trying to use embedded fonts (Flex 4.6) in a UITextField. As long as I use a font that is registered with Windows, it works fine, but for a font not registered, the UITextField defaults to TimesRoman (or something similar)

Note that when I check to see if the font is embedded, it returns True (FlexGlobals.topLevelApplication.systemManager.isFontFaceEmbedded(txtFormatCoda))

So what am I missing?

In the code below, if I add the font Kredit to Windows Font, the UI text field appears in Kredit font, but if I remove it from Windows/font directory, the field appears in TimesNewRoman (default font).

<?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>
解决方案

Thanks Mahesh

Actually this worked for me:

var comp:UIComponent = new UIComponent();
comp.setStyle('fontFamily', fontName);

Basically I had to do setStyle on the UIComponent which is the parent of this UITextField. I wish Adobe would document this.

这篇关于Flex 4.6:嵌入的字体不适用于TextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 09:24