在 Flex 的 ActionScript 类中嵌入字体

发布于 2024-10-27 16:17:59 字数 204 浏览 5 评论 0原文

创建 mxml 组件时,可以轻松地以这种方式嵌入所需的字体:

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

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

问候,拉法尔

When creating an mxml component it is easy to embed the desired font in this way:

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

In my code I need to embed the font for a component that is the part of the class implemented in *.as file. How can I do this?

Regards, Rafal

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

极度宠爱 2024-11-03 16:17:59

几周前我在我的网站上介绍了这一点。这里有太多信息需要复制/粘贴,因此您可以在以下位置获取:http://divillysausages.com/blog/ as3_font_embedding_masterclass

有代码&源文件也是如此。如果您有任何问题,请告诉我。

I covered this a few weeks ago on my site. There's too much info to copy/paste here, so you can get it at: http://divillysausages.com/blog/as3_font_embedding_masterclass

There's code & source files as well. Let me know if you have any problems.

疧_╮線 2024-11-03 16:17:59

以下是如何在自定义 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。但是您可以使用样式以类似的方式使用标签。

示例用法如下:

<?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>

希望这有帮助。

Here is the simple sample how you can embed font in custom ActionScript component:

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;
    }
}
}

I omitted real measurement for simplicity. So the code is pretty simple and uses very lightweight UITextField. But you can use Label the similar way using styling.

The sample usage is the following:

<?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>

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文