Flex 4.6:嵌入字体不适用于 TextField [英] Flex 4.6: embedded fonts not applied to TextField

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

问题描述

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

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)

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

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

那我错过了什么?

在下面的代码中,如果我将字体 Kredit 添加到 Windows Font,UI 文本字段以 Kredit 字体显示,但如果我从 Windows/font 目录中删除它,该字段将显示为 TimesNewRoman(默认字体).

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>

推荐答案

感谢 Mahesh

实际上这对我有用:

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

基本上,我必须在作为此 UITextField 的父级的 UIComponent 上执行 setStyle.我希望 Adob​​e 能记录下来.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆