检测用户系统中安装的字体

<? xml version="1.0" encoding="utf-8" ?>
<!--  http://blog.flexexamples.com/2007/09/10/finding-out-which-fonts-are-installed-on-a-users-system/  -->
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white"
        creationComplete
="init()" >

    
< mx:Script >
        
<![CDATA[
            import flash.text.Font;

            private function init():void {
                arr = Font.enumerateFonts(true);
                arr.sortOn("fontName", Array.CASEINSENSITIVE);
            }
        
]]>
    
</ mx:Script >

    
< mx:Array  id ="arr"   />
    
< mx:String  id ="str" > The quick brown fox jumped over the lazy dog. </ mx:String >

    
< mx:ApplicationControlBar  dock ="true" >
        
< mx:Label  text ="String:"   />
        
< mx:TextInput  id ="textInput"  text ="{str}"   />

        
< mx:Spacer  width ="100%"   />

        
< mx:Label  text ="Number of installed fonts: {arr.length}"   />
    
</ mx:ApplicationControlBar >

    
< mx:DataGrid  id ="dataGrid"  dataProvider ="{arr}" >
        
< mx:columns >
            
< mx:DataGridColumn  dataField ="fontName"
                    width
="200"
                    itemRenderer
="mx.controls.Label"   />
            
< mx:DataGridColumn  dataField ="fontStyle"   />
            
< mx:DataGridColumn  dataField ="fontType"   />
        
</ mx:columns >
    
</ mx:DataGrid >

    
< mx:Label  id ="lbl"
            text
="{textInput.text}"
            width
="{dataGrid.width}"
            height
="32"
            fontFamily
="{dataGrid.selectedItem.fontName}"
            fontSize
="16"   />

</ mx:Application >
 

效果:


如果修改上面的例子,并使用下面的代码嵌入一个字体,那么在表格中也会显示出来“Base02"字体:


< mx:Style >
    @font-face{
        src: url("./fonts/base02.ttf");
        fontFamily: "Base02";
    }
</ mx:Style >

如果把 enumerateFonts()方法的参数改为flase,那么只会列举出嵌入字体:

< mx:Script >
    
<![CDATA[
        import flash.text.Font;

        private function init():void {
            arr = Font.enumerateFonts(false);
            arr.sortOn("fontName", Array.CASEINSENSITIVE);
        }
    
]]>
</ mx:Script >

你可能感兴趣的:(Blog,Flash,Adobe)