<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; enumerateFonts()</title>
	<atom:link href="http://blog.flexexamples.com/tag/enumeratefonts/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Determining whether a font has specific glyphs in Flex</title>
		<link>http://blog.flexexamples.com/2008/01/31/determining-whether-a-font-has-specific-glyphs-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/01/31/determining-whether-a-font-has-specific-glyphs-in-flex/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 08:36:07 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[enumerateFonts()]]></category>
		<category><![CDATA[hasGlyphs()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/01/31/determining-whether-a-font-has-specific-glyphs-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can check whether an embedded font has a specific glyph by passing a string to the hasGlyph() method which returns a Boolean value indicating whether the font has the specified character(s).</p> <p>Full code after the jump.</p> <p></p> <p class="construction">To filter the fonts by glyph, type a few characters into [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can check whether an embedded font has a specific glyph by passing a string to the hasGlyph() method which returns a Boolean value indicating whether the font has the specified character(s).</p>
<p>Full code after the jump.</p>
<p><span id="more-498"></span></p>
<p class="construction">To filter the fonts by glyph, type a few characters into the &#8220;Chars&#8221; text input. If a font does not have the specified characters it will be removed from the font list. Each of the fonts have the traditional A-Z, 0-9, so to see the filtering in all its glory, try typing &#8220;#&#8221; or &#8220;$&#8221; and the embedded &#8216;Base 02&#8242; font should disappear from the list.</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Font_hasGlyphs_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/01/31/determining-whether-a-font-has-specific-glyphs-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="horizontal"
        verticalAlign="top"
        backgroundColor="white"
        initialize="init();"&gt;

    &lt;mx:Style source="fonts.css" /&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.events.ListEvent;

            private const START:uint = 0x0020;
            private const END:uint = 0x007E;

            private function init():void {
                arr = Font.enumerateFonts(false)
                arrColl.source = arr;

                var str:String = "";
                var idx:uint;
                for (idx = START; idx &lt; END; idx++) {
                    str += String.fromCharCode(idx);
                }
                textArea.text = str;
            }

            private function arrColl_filterFunc(item:Font):Boolean {
                return item.hasGlyphs(textInput.text);
            }

            private function list_rollOut(evt:MouseEvent):void {
                var f:Font = List(evt.currentTarget).selectedItem as Font;
                if (!f) {
                    // No selected item, abort!
                    return;
                }
                textArea.setStyle("fontFamily", f.fontName);
                samplePanel.title = "Sample: " + f.fontName;
            }

            private function list_itemClick(evt:ListEvent):void {
                var f:Font = List(evt.currentTarget).selectedItem as Font;
                if (!f) {
                    // No selected item, abort!
                    return;
                }
                textArea.setStyle("fontFamily", f.fontName);
                samplePanel.title = "Sample: " + f.fontName;
            }

            private function list_rollOver(evt:ListEvent):void {
                var f:Font = evt.itemRenderer.data as Font;
                textArea.setStyle("fontFamily", f.fontName);
                samplePanel.title = "Sample: " + f.fontName;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Array id="arr" /&gt;

    &lt;mx:ArrayCollection id="arrColl"
            filterFunction="arrColl_filterFunc"&gt;
        &lt;mx:sort&gt;
            &lt;mx:Sort&gt;
                &lt;mx:SortField name="fontName"
                        caseInsensitive="true" /&gt;
            &lt;/mx:Sort&gt;
        &lt;/mx:sort&gt;
    &lt;/mx:ArrayCollection&gt;

    &lt;mx:Panel id="panel"
            title="Fonts:"
            status="{arrColl.length}/{arr.length}"&gt;
        &lt;mx:List id="list"
                dataProvider="{arrColl}"
                labelField="fontName"
                width="100%"
                rowCount="{arr.length}"
                itemClick="list_itemClick(event);"
                itemRollOver="list_rollOver(event);"
                rollOut="list_rollOut(event);"&gt;
            &lt;mx:itemRenderer&gt;
                &lt;mx:Component&gt;
                    &lt;mx:Label fontFamily="{data.fontName}" /&gt;
                &lt;/mx:Component&gt;
            &lt;/mx:itemRenderer&gt;
        &lt;/mx:List&gt;
        &lt;mx:ControlBar&gt;
            &lt;mx:Label text="Chars:" /&gt;
            &lt;mx:TextInput id="textInput"
                    width="90"
                    change="arrColl.refresh();" /&gt;
        &lt;/mx:ControlBar&gt;
    &lt;/mx:Panel&gt;

    &lt;mx:Panel id="samplePanel"
            title="Sample:"
            width="100%"
            height="100%"&gt;
        &lt;mx:TextArea id="textArea"
                fontSize="{slider.value}"
                color="black"
                letterSpacing="10"
                width="100%"
                height="100%" /&gt;
        &lt;mx:ControlBar&gt;
            &lt;mx:Label text="Font size:" /&gt;
            &lt;mx:HSlider id="slider"
                    minimum="10"
                    maximum="60"
                    value="20"
                    snapInterval="1"
                    tickInterval="4"
                    liveDragging="true"
                    width="100%" /&gt;
        &lt;/mx:ControlBar&gt;
    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Font_hasGlyphs_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/Font_hasGlyphs_test/bin/main.html" width="100%" height="500"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Determining whether a font has specific glyphs in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/01/31/determining-whether-a-font-has-specific-glyphs-in-flex/',contentID: 'post-498',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'enumerateFonts(),hasGlyphs()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/01/31/determining-whether-a-font-has-specific-glyphs-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding out which fonts are installed on a user&#8217;s system</title>
		<link>http://blog.flexexamples.com/2007/09/10/finding-out-which-fonts-are-installed-on-a-users-system/</link>
		<comments>http://blog.flexexamples.com/2007/09/10/finding-out-which-fonts-are-installed-on-a-users-system/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 14:25:24 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[Font]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[enumerateFonts()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/09/10/finding-out-which-fonts-are-installed-on-a-users-system/</guid>
		<description><![CDATA[<p>The following example shows how you can use the static Font.enumerateFonts() method in Flex to determine which fonts are installed on a user&#8217;s system. The enumerateFonts() method returns an array of Font objects (see the flash.text.Font for more information)</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Font_enumerateFonts_test/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2007/09/10/finding-out-which-fonts-are-installed-on-a-users-system/ --&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can use the static <code>Font.enumerateFonts()</code> method in Flex to determine which fonts are installed on a user&#8217;s system. The <code>enumerateFonts()</code> method returns an array of Font objects (see the flash.text.Font for more information)</p>
<p>Full code after the jump.</p>
<p><span id="more-165"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Font_enumerateFonts_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/09/10/finding-out-which-fonts-are-installed-on-a-users-system/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init()"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import flash.text.Font;

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

    &lt;mx:Array id="arr" /&gt;
    &lt;mx:String id="str"&gt;The quick brown fox jumped over the lazy dog.&lt;/mx:String&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Label text="String:" /&gt;
        &lt;mx:TextInput id="textInput" text="{str}" /&gt;

        &lt;mx:Spacer width="100%" /&gt;

        &lt;mx:Label text="Number of installed fonts: {arr.length}" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

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

    &lt;mx:Label id="lbl"
            text="{textInput.text}"
            width="{dataGrid.width}"
            height="32"
            fontFamily="{dataGrid.selectedItem.fontName}"
            fontSize="16" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Font_enumerateFonts_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/Font_enumerateFonts_test/bin/main.html" width="100%" height="300"></iframe></p>
<p>Note that in the previous example, we passed a value of <code>true</code> to the <code>enumerateFonts()</code> method. The <code>enumerateFonts()</code> method takes a single Boolean parameter, <code>enumerateDeviceFonts</code> (default value is <code>false</code>), which controls whether both device and embedded fonts are returned (<code>true</code>) or whether just embedded fonts are returned (<code>false</code>).</p>
<p>If you modified the previous example and embedded a font using the following code, you would see that an additional font &#8220;Base02&#8243; appears in the data grid:</p>
<pre class="code">
&lt;mx:Style&gt;
    @font-face{
        src: url("./fonts/base02.ttf");
        fontFamily: "Base02";
    }
&lt;/mx:Style&gt;
</pre>
<p>Also, if you modified the &lt;mx:Script /&gt; tag and passed <code>false</code> to the <code>enumerateFonts()</code> method, only one item would be displayed in the data grid (fontName:&#8221;Base02&#8243;, fontStyle:&#8221;regular&#8221;, fontType:&#8221;embedded&#8221;):</p>
<pre class="code">
&lt;mx:Script&gt;
    &lt;![CDATA[
        import flash.text.Font;

        private function init():void {
            arr = Font.enumerateFonts(<strong style="color:red;">false</strong>);
            arr.sortOn(&quot;fontName&quot;, Array.CASEINSENSITIVE);
        }
    ]]&gt;
&lt;/mx:Script&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Finding out which fonts are installed on a user\&#039;s system on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/09/10/finding-out-which-fonts-are-installed-on-a-users-system/',contentID: 'post-165',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'enumerateFonts()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/09/10/finding-out-which-fonts-are-installed-on-a-users-system/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

