[转]Flex应用中利用Embed metadata(redux)的systemFont属性嵌入字体(font)的例子

http://blog.minidx.com/2008/04/02/675.html

在前面的Flex应用中如何利用source属性嵌入字体的例子中,我们了解了Flex应用中如何利用[Embed]metadata的source属性嵌入字体,接下来的例子演示了如何利用Embedmetadata(redux)的systemFont属性嵌入字体。

让我们先来看一下Demo(可以右键ViewSource或点击这里察看源代码):

下面是完整代码(或点击这里察看):

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Style>
        .regularFontStyle {
            fontFamily: regularFont;
        }
 
        .italicFontStyle {
            fontFamily: italicFont;
            fontStyle: italic;
        }
    </mx:Style>
 
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.utils.ObjectUtil;
 
            [Bindable]
            [Embed("bulletWarning.png")]
            private var bulletWarningIcon:Class;
 
            [Embed(systemFont="Tahoma",
                    fontName="regularFont",
                    mimeType="application/x-font")]
            private var font1:Class;
 
            [Embed(systemFont="Tahoma",
                    fontName="italicFont",
                    fontStyle="italic",
                    advancedAntiAliasing="true",
                    mimeType="application/x-font")]
            private var font2:Class;
 
            private function displayEmbeddedFont(name:String):void {
                var font:Object = systemManager.embeddedFontList[name];
                Alert.show(ObjectUtil.toString(font), name + ":");
            }
        ]]>
    </mx:Script>
 
    <mx:Form>
        <mx:FormItem label="regularFont:" direction="horizontal">
            <mx:Label id="lbl1"
                    text="The quick brown fox jumped over the lazy dog."
                    styleName="regularFontStyle" />
            <mx:Image source="{bulletWarningIcon}"
                    click="displayEmbeddedFont('regularFont');" />
        </mx:FormItem>
        <mx:FormItem label="italicFont:" direction="horizontal">
            <mx:Label id="lbl2"
                    text="The quick brown fox jumped over the lazy dog."
                    styleName="italicFontStyle" />
            <mx:Image source="{bulletWarningIcon}"
                    click="displayEmbeddedFont('italicFont');" />
        </mx:FormItem>
    </mx:Form>
 
</mx:Application>

相关推荐