【问题标题】:Embed font in ActionScript class in Flex在 Flex 的 ActionScript 类中嵌入字体
【发布时间】:2011-07-25 23:56:23
【问题描述】:

在创建 mxml 组件时,很容易以这种方式嵌入所需的字体:

@font-face {
    src: local("Arial");
    fontFamily: ArialEmbedded;
}

在我的代码中,我需要为一个组件嵌入字体,该组件是在 *.as 文件中实现的类的一部分。我该怎么做?

问候,拉法尔

【问题讨论】:

    标签: apache-flex actionscript fonts embed


    【解决方案1】:

    几周前,我在我的网站上介绍了这一点。此处复制/粘贴的信息太多,您可以通过以下网址获取:http://divillysausages.com/blog/as3_font_embedding_masterclass

    还有代码和源文件。如果您有任何问题,请告诉我。

    【讨论】:

    【解决方案2】:

    以下是如何在自定义 ActionScript 组件中嵌入字体的简单示例:

    package
    {
    import flash.display.DisplayObject;
    
    import mx.core.IUITextField;
    import mx.core.UIComponent;
    import mx.core.UITextField;
    
    [Style(name="fontFamily", type="String", inherit="yes")]
    public class ComponentWithFontEmbedding extends UIComponent
    {
        private var label:IUITextField;
    
        override protected function createChildren():void
        {
            super.createChildren();
    
            if (!label)
            {
                label = IUITextField(createInFontContext(UITextField));
                label.styleName = this;
                addChild(DisplayObject(label));
                label.text = "Hello";
            }
        }
    
        override protected function measure():void
        {
            measuredWidth = measuredMinWidth = 100;
            measuredHeight = measuredMinHeight = 50;
        }
    }
    }
    

    为简单起见,我省略了实际测量。所以代码非常简单,并且使用了非常轻量级的 UITextField。但是您可以使用样式以类似的方式使用 Label。

    示例用法如下:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" xmlns:local="*">
        <mx:Style>
            @font-face {
                src: local("Arial");
                fontFamily: ArialEmbedded;
            }
        </mx:Style>
        <local:ComponentWithFontEmbedding fontFamily="ArialEmbedded" verticalCenter="0" horizontalCenter="0" />
    </mx:Application>
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-06
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      • 2012-05-01
      • 1970-01-01
      • 2010-11-02
      • 1970-01-01
      相关资源
      最近更新 更多