<?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>Gaurav&#039;s Blog &#187; Fonts</title>
	<atom:link href="http://gauravj.com/blog/tag/fonts/feed/" rel="self" type="application/rss+xml" />
	<link>http://gauravj.com/blog</link>
	<description>Tips and Tools of Flex</description>
	<lastBuildDate>Thu, 18 Mar 2010 18:34:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Creating smaller swfs (Part III)</title>
		<link>http://gauravj.com/blog/2009/07/creating-smaller-swfs-part-iii/</link>
		<comments>http://gauravj.com/blog/2009/07/creating-smaller-swfs-part-iii/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 19:41:15 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Framework]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[RSL]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=376</guid>
		<description><![CDATA[<p>Here is the part three.. </p>
<p>The very fact that you are writing applications using Flex proves that you care about user interface. And one of the features of Flex that enables you to provide a better user experience is font embedding. There are many benefits of using embedded fonts but the most important one is that <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2009/07/creating-smaller-swfs-part-iii/">Creating smaller swfs (Part III)</a></span>]]></description>
			<content:encoded><![CDATA[<p>Here is the part three.. </p>
<p>The very fact that you are writing applications using Flex proves that you care about user interface. And one of the features of Flex that enables you to provide a better user experience is font embedding. There are many benefits of using embedded fonts but the most important one is that it provides consistency regarding how the application will appear across different client environments and you don&#8217;t need to make sure whether the font is pre-installed. But there can also be few disadvantages of using embedded fonts, like when you use embedded font it gets stitched into your SWF which results in increasing the overall size of the SWF. </p>
<p>So lets look at how you can reap the benefits of using embedded fonts while still avoiding the start up time cost due to a larger SWF. The trick for doing this is to use Modules (for embedding fonts) and avoid embedding the fonts in the main SWF. That way you can achieve smaller start up time and fetch the fonts when you need to use them.</p>
<p>Here is an example of an application that displays text using four different fonts: </p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> </span>
<span style="color: #000000;">		layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> width=<span style="color: #ff0000;">&quot;650&quot;</span> height=<span style="color: #ff0000;">&quot;400&quot;</span></span>
<span style="color: #000000;">		verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> </span>
<span style="color: #000000;">		creationComplete=<span style="color: #ff0000;">&quot;creationCompleteHandler(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">		&lt;![CDATA[</span>
<span style="color: #339933;">			import mx.events.ModuleEvent;</span>
<span style="color: #339933;">			import mx.modules.ModuleManager;</span>
<span style="color: #339933;">			import mx.modules.IModuleInfo;</span>
<span style="color: #339933;">			import mx.events.FlexEvent;</span>
<span style="color: #339933;">			import mx.controls.Alert;</span>
<span style="color: #339933;">			import mx.validators.Validator;</span>
<span style="color: #339933;">			private var fontModuleInfo:IModuleInfo;</span>
&nbsp;
<span style="color: #339933;">			protected function button_clickHandler(event:MouseEvent):void {</span>
<span style="color: #339933;">				if(currentState != 'LoggedIn') {</span>
<span style="color: #339933;">					var validators:Array = [];</span>
<span style="color: #339933;">					validators[0] = this.v0;</span>
<span style="color: #339933;">					validators[1] = this.v1;</span>
&nbsp;
<span style="color: #339933;">					var inValid:Array = Validator.validateAll(validators);</span>
<span style="color: #339933;">					if(inValid.length ==0) {</span>
<span style="color: #339933;">						if(tiUserName.text == 'guest' </span>
<span style="color: #339933;">							&amp;&amp; tiPassword.text =='guest') {</span>
<span style="color: #339933;">							currentState = 'LoggedIn';</span>
<span style="color: #339933;">						} else {</span>
<span style="color: #339933;">							Alert.show(&quot;Invalid username&quot; +</span>
<span style="color: #339933;">								&quot; or password.&quot;); </span>
<span style="color: #339933;">						}</span>
<span style="color: #339933;">					}</span>
<span style="color: #339933;">				} else {</span>
<span style="color: #339933;">					currentState = '';</span>
<span style="color: #339933;">				}</span>
<span style="color: #339933;">			}</span>
&nbsp;
<span style="color: #339933;">			protected function creationCompleteHandler(event:FlexEvent):void </span>
<span style="color: #339933;">			{</span>
<span style="color: #339933;">				fontModuleInfo = ModuleManager.getModule(&quot;FontModule.swf&quot;);</span>
<span style="color: #339933;">				fontModuleInfo.addEventListener(ModuleEvent.READY,</span>
<span style="color: #339933;">					readyHandler);</span>
<span style="color: #339933;">				fontModuleInfo.load();</span>
<span style="color: #339933;">			}</span>
&nbsp;
<span style="color: #339933;">			private function readyHandler(event:Event):void {</span>
<span style="color: #339933;">				fontModuleInfo.factory.create();</span>
<span style="color: #339933;">			}</span>
&nbsp;
<span style="color: #339933;">		]]&gt;</span>
<span style="color: #339933;">	&lt;/mx:Script&gt;</span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:StringValidator</span> source=<span style="color: #ff0000;">&quot;{tiUserName}&quot;</span> property=<span style="color: #ff0000;">&quot;text&quot;</span> id=<span style="color: #ff0000;">&quot;v0&quot;</span></span>
<span style="color: #000000;">						required=<span style="color: #ff0000;">&quot;true&quot;</span> maxLength=<span style="color: #ff0000;">&quot;10&quot;</span> </span>
<span style="color: #000000;">						trigger=<span style="color: #ff0000;">&quot;{loginButton}&quot;</span> triggerEvent=<span style="color: #ff0000;">&quot;click&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:StringValidator</span> source=<span style="color: #ff0000;">&quot;{tiPassword}&quot;</span> property=<span style="color: #ff0000;">&quot;text&quot;</span> id=<span style="color: #ff0000;">&quot;v1&quot;</span></span>
<span style="color: #000000;">						required=<span style="color: #ff0000;">&quot;true&quot;</span> maxLength=<span style="color: #ff0000;">&quot;10&quot;</span> </span>
<span style="color: #000000;">						trigger=<span style="color: #ff0000;">&quot;{loginButton}&quot;</span> triggerEvent=<span style="color: #ff0000;">&quot;click&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:states</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:State</span> name=<span style="color: #ff0000;">&quot;LoggedIn&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RemoveChild</span> target=<span style="color: #ff0000;">&quot;{loginPanel}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:AddChild</span> relativeTo=<span style="color: #ff0000;">&quot;{loginButton}&quot;</span> position=<span style="color: #ff0000;">&quot;before&quot;</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Panel</span> id=<span style="color: #ff0000;">&quot;pnl&quot;</span> title=<span style="color: #ff0000;">&quot;Labels with different fonts. </span>
<span style="color: #000000;">						  Embedded fonts can be rotated.&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;10&quot;</span> </span>
<span style="color: #000000;">						  paddingBottom=<span style="color: #ff0000;">&quot;10&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;10&quot;</span> paddingRight=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #7400FF;">&gt;</span></span>
					<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> id=<span style="color: #ff0000;">&quot;lblVerdana&quot;</span> </span>
<span style="color: #000000;">						  styleName=<span style="color: #ff0000;">&quot;myVerdanaDescriptor&quot;</span> rotation=<span style="color: #ff0000;">&quot;1&quot;</span>  </span>
<span style="color: #000000;">						  text=<span style="color: #ff0000;">&quot;The quick brown fox jumps over the lazy dog.&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
					<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> id=<span style="color: #ff0000;">&quot;lblCandara&quot;</span> </span>
<span style="color: #000000;">						  styleName=<span style="color: #ff0000;">&quot;myCandaraDescriptor&quot;</span> rotation=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #000000;">						  text=<span style="color: #ff0000;">&quot;The quick brown fox jumps over the lazy dog.&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
					<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> id=<span style="color: #ff0000;">&quot;lblVrinda&quot;</span> </span>
<span style="color: #000000;">						  styleName=<span style="color: #ff0000;">&quot;myVrindaDescriptor&quot;</span> rotation=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #000000;">						  text=<span style="color: #ff0000;">&quot;The quick brown fox jumps over the lazy dog.&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
					<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> id=<span style="color: #ff0000;">&quot;lblMinion&quot;</span> </span>
<span style="color: #000000;">						  styleName=<span style="color: #ff0000;">&quot;myMinionDescriptor&quot;</span> rotation=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #000000;">						  text=<span style="color: #ff0000;">&quot;The quick brown fox jumps over the lazy dog.&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Panel</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SetProperty</span> target=<span style="color: #ff0000;">&quot;{loginButton}&quot;</span> </span>
<span style="color: #000000;">							name=<span style="color: #ff0000;">&quot;label&quot;</span> value=<span style="color: #ff0000;">&quot;Log Out&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:State</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Panel</span> id=<span style="color: #ff0000;">&quot;loginPanel&quot;</span> </span>
<span style="color: #000000;">			  title=<span style="color: #ff0000;">&quot;Login&quot;</span>  borderAlpha=<span style="color: #ff0000;">&quot;0.15&quot;</span></span>
<span style="color: #000000;">			  horizontalScrollPolicy=<span style="color: #ff0000;">&quot;off&quot;</span> verticalScrollPolicy=<span style="color: #ff0000;">&quot;off&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Form</span> id=<span style="color: #ff0000;">&quot;loginForm&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:FormItem</span> label=<span style="color: #ff0000;">&quot;Username:&quot;</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:TextInput</span> id=<span style="color: #ff0000;">&quot;tiUserName&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:FormItem</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:FormItem</span> label=<span style="color: #ff0000;">&quot;Password:&quot;</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:TextInput</span> id=<span style="color: #ff0000;">&quot;tiPassword&quot;</span> </span>
<span style="color: #000000;">							  displayAsPassword=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:FormItem</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Form</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Panel</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Login&quot;</span> id=<span style="color: #ff0000;">&quot;loginButton&quot;</span> </span>
<span style="color: #000000;">			   click=<span style="color: #ff0000;">&quot;button_clickHandler(event)&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

</blockquote>
<p>And here is the module (FontModule.mxml) used to embed fonts:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Module</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Style</span><span style="color: #7400FF;">&gt;</span></span>
		@font-face {
			src:url(&quot;verdana.TTF&quot;);
			fontFamily: myVerdana;
		}
&nbsp;
		.myVerdanaDescriptor
		{
			fontFamily: myVerdana;
			color: red;
			fontSize: 24;
		}
&nbsp;
		@font-face {
			src:url(&quot;MinionPro-Regular.otf&quot;);
			fontFamily: myMinion;
		}
&nbsp;
		.myMinionDescriptor
		{
			fontFamily: myMinion;
			color: green;
			fontSize: 24;
		}
&nbsp;
		@font-face {
			src:url(&quot;Vrinda.ttf&quot;);
			fontFamily: myVrinda;
		}
&nbsp;
		.myVrindaDescriptor
		{
			fontFamily: myVrinda;
			color: red;
			fontSize: 24;
		}
&nbsp;
		@font-face {
			src:url(&quot;CANDARA.TTF&quot;);
			fontFamily: myCandara;
		}
&nbsp;
		.myCandaraDescriptor
		{
			fontFamily: myCandara;
			color: green;
			fontSize: 24;
		}
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Style</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Module</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

</blockquote>
<p>Below is the running sample, to log in <strong>use &#8220;guest&#8221; as user name and password</strong> and click on the button.<br />
<center><br />
<iframe src ="http://gauravj.com/blog/examples/Modules/Fonts/Sample.html" width="650" height="400"></p>
<p>Your browser does not support iframes.</p>
<p></iframe><br />
</center></p>
<p>The size benefits:</p>
<table border="1">
<tr>
<th>Configuration</th>
<th>Swf size</th>
<th>Comments</th>
</tr>
<tr>
<td>If fonts are embedded in main swf</td>
<td>607 KB</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>If fonts are fonts embedded in module</td>
<td>267 KB</td>
<td>The font Module is 354 KB</td>
</tr>
<tr>
<td>If fonts are fonts embedded in module and main app uses default SDK RSLs. (as is the case with the above example)</td>
<td>84 KB</td>
<td>This app was compiled with Flex 4 beta build. With a more recent Flex 4 build there should be increased benefits for swf size reduction.</td>
</tr>
</table>
<p>So we trimmed the SWF by 86% for this sample.</p>
<p>The above approach works if you don&#8217;t need embedded fonts right at the application start up. In the above example the font module is loaded after the main app is initialized, as we don&#8217;t need to show text using embedded fonts on the log in screen. This way the user experiences a reduced start up time and you can still use the fonts you like <img src='http://gauravj.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>If you app uses multiple fonts and some of them are not required at the application start up, consider embedding fonts in a module.</p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2009/07/creating-smaller-swfs-part-iii/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
