<?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; hasGlyphs()</title>
	<atom:link href="http://blog.flexexamples.com/tag/hasglyphs/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>
	</channel>
</rss>

