【问题标题】:Flex 4.6: embedded fonts not applied to TextFieldFlex 4.6:嵌入字体不适用于 TextField
【发布时间】:2012-07-31 03:25:57
【问题描述】:

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

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

那么我错过了什么?

在下面的代码中,如果我将字体 Kredit 添加到 Windows Font,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>

【问题讨论】:

    标签: apache-flex fonts embed


    【解决方案1】:

    下面的代码可能会对你有所帮助: - 我已经注释了一行并修改了样式标签...

    <?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>
            @namespace s "library://ns.adobe.com/flex/spark";
            @namespace mx "library://ns.adobe.com/flex/mx";
    
             @font-face {
                src: url("fonts/KREDIT1.TTF");
                fontFamily: KREDIT1;
                embed-as-cff: false;
                advancedAntiAliasing:true;
            } 
    
            s|Application
            {
                fontFamily:KREDIT1;
            }
        </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>
    

    【讨论】:

    • 感谢 Mahesh 没有机会尝试您的解决方案,因为以下方法有效:
    【解决方案2】:

    感谢马赫什

    实际上这对我有用:

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

    基本上我必须在 UIComponent 上做 setStyle,它是这个 UITextField 的父级。我希望 Adob​​e 会记录这一点。

    【讨论】:

      猜你喜欢
      • 2012-09-10
      • 1970-01-01
      • 2015-03-22
      • 2013-07-17
      • 2013-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多