<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Gregory's Technical Tidbits</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/gsmith/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/gsmith/feed.xml</link>
    <description>Random software and technological musings, tips and tidbits from the mind of a geek.</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:23:11 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Coloring and Scaling SVG in a WinJS.Binding.Template Control</title>
      <link>https://docs.microsoft.com/archive/blogs/gsmith/coloring-and-scaling-svg-in-a-winjs-binding-template-control</link>
      <pubDate>Sun, 28 Oct 2012 22:37:00 GMT</pubDate>
      <dc:creator><![CDATA[Gregory W. Smith]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/gsmith/2012/10/28/coloring-and-scaling-svg-in-a-winjs-binding-template-control/</guid>
      <description><![CDATA[When creating my Windows Store application Gamer Dice, I wanted to provide a compelling visual...]]></description>
      <content:encoded><![CDATA[<p>When creating my Windows Store application <a title="Windows Store - Gamer Dice" href="http://apps.microsoft.com/webpdp/en-US/app/gamer-dice/f414dc79-446b-44ca-9e73-240b14c3fda3" target="_blank">Gamer Dice</a>, I wanted to provide a compelling visual representation of the dice the player was using that scaled well when the dice were shown at different sizes, in different colors (tints) and could show the numeric result of the roll. After thinking about a number of different approaches, the one chosen uses SVG to describe the shape of the die in a <a title="WinJS.Binding.Template object" href="http://msdn.microsoft.com/en-us/library/windows/apps/br229723.aspx" target="_blank">WinJS.Binding.Template</a> control, and binds the size, color and value of the die. This post illustrates how to use this pattern in a Win8 JavaScript application. I’m going to assume working knowledge of <a title="Windows Store apps using JavaScript" href="http://msdn.microsoft.com/library/windows/apps/hh465037" target="_blank">Windows Web Applications</a> (WWA) and <a title="SVG Primer" href="http://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html" target="_blank">Scalable Vector Graphics</a> (SVG).</p><h2>Declare the Template</h2><p>In the HTML markup of the page declare the WinJS.Binding.Template control that will include the SVG fragment to be used. Blend for Visual Studio may be used to quickly add a Template Control to a page.</p><p>In the Asset panel, select the JavaScript Controls category and double-click Template control to add it. Alternatively, you can search for the Template control using the Search Assets filter in the Asset panel. Once the template is added, replace the text “Place content here” with the &lt;svg&gt; content you want to include as part of the template. Here’s what it would look like in Blend:</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/metablogapi/0410.image_47DA1031.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-98-19-metablogapi/0410.image_5F00_47DA1031.png"><img width="845" height="407" title="image" style="display: inline; background-image: none;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/metablogapi/2134.image_thumb_15763CB2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-98-19-metablogapi/2134.image_5F00_thumb_5F00_15763CB2.png" border="0"></a></p><p>In Visual Studio the markup will look something like this:</p><pre class="code"><span style="background: white; color: blue;">&lt;</span><span style="background: white; color: maroon;">div </span><span style="background: white; color: red;">data-win-control</span><span style="background: white; color: blue;">="WinJS.Binding.Template"&gt;</span></pre><pre class="code"><span style="background: white; color: blue;">   &lt;</span><span style="background: white; color: maroon;">div</span><span style="background: white; color: blue;">&gt;
</span></pre><pre class="code"><span style="background: white; color: blue;">       &lt;</span><span style="background: white; color: maroon;">svg </span><span style="background: white; color: red;">width</span><span style="background: white; color: blue;">="328.78506" </span><span style="background: white; color: red;">height</span><span style="background: white; color: blue;">="325.80728" &gt;
         &lt;</span><span style="background: white; color: maroon;">g </span><span style="background: white; color: red;">transform</span><span style="background: white; color: blue;">="translate(-211.01766,-268.64704)"&gt;
           &lt;</span><span style="background: white; color: maroon;">path </span><span style="background: white; color: red;">style</span><span style="background: white; color: blue;">="</span><span style="background: white; color: red;">fill</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">#ff6262</span><span style="background: white; color: black;">;</span><span style="background: white; color: red;">fill-opacity</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">1</span><span style="background: white; color: black;">;</span><span style="background: white; color: red;">stroke</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">none</span><span style="background: white; color: black;">;</span><span style="background: white; color: blue;">"
                 </span><span style="background: white; color: red;">d</span><span style="background: white; color: blue;">="m 483.39049,436.95746 …"
                 </span><span style="background: white; color: red;">transform</span><span style="background: white; color: blue;">="matrix(1.4592076,0,0,1.4396496,-165.56435,-197.51494)" &gt;
           &lt;/</span><span style="background: white; color: maroon;">path</span><span style="background: white; color: blue;">&gt;    
           &lt;</span><span style="background: white; color: maroon;">path </span><span style="background: white; color: red;">style</span><span style="background: white; color: blue;">="</span><span style="background: white; color: red;">fill</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">#990000</span><span style="background: white; color: black;">;</span><span style="background: white; color: red;">fill-opacity</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">1</span><span style="background: white; color: black;">;</span><span style="background: white; color: red;">stroke</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">none</span><span style="background: white; color: black;">;</span><span style="background: white; color: blue;">"
                 </span><span style="background: white; color: red;">d</span><span style="background: white; color: blue;">="m 483.39049,436.95746 …"
                 </span><span style="background: white; color: red;">transform</span><span style="background: white; color: blue;">="matrix(1.3314543,0,0,1.3256145,-118.29482,-148.35441)" &gt;
           &lt;/</span><span style="background: white; color: maroon;">path</span><span style="background: white; color: blue;">&gt;    
           &lt;</span><span style="background: white; color: maroon;">path </span><span style="background: white; color: red;">style</span><span style="background: white; color: blue;">="</span><span style="background: white; color: red;">fill</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">#ff0000</span><span style="background: white; color: black;">;</span><span style="background: white; color: red;">fill-opacity</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">1</span><span style="background: white; color: black;">;</span><span style="background: white; color: red;">stroke</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">none</span><span style="background: white; color: black;">;</span><span style="background: white; color: blue;">"
                 </span><span style="background: white; color: red;">d</span><span style="background: white; color: blue;">="m 328.54672,425.0464 …"
                 </span><span style="background: white; color: red;">transform</span><span style="background: white; color: blue;">="translate(122.13283,111.14024)" &gt;<br></span><span style="background: white; color: blue;">           &lt;/</span><span style="background: white; color: maroon;">path</span><span style="background: white; color: blue;">&gt;
</span></pre><p>&nbsp;</p><p>Keep in mind that the contents of the template are not shown in the application until they are bound to something. Also, whatever SVG code is used will be duplicated over and over as the template is applied and the larger and more complex template, the more complex the resulting DOM. So care should be taken to minimize and simplify the SVG markup as much as possible. Many of the tools used to manipulate the SVG add elements to the markup that only have meaning at design time, and while this excessive SVG renders as expected in IE or WWA, there is far more markup than is necessary to get the desired effect.</p><h2>Value Converters</h2><p>Often in data binding, the format of the source data doesn’t match the output or doesn’t match naturally to the parts of the UI to which it is bound. A classic example is the coloring of a number as black or red depending on if it’s positive or negative. The output of the expression would be a Boolean (e.g. value &gt;= 0) but the UI really wants to bind to a color, in this case, red or black. A value converter is a function you provide that computes the desired from the context of the data and properties being bound.</p><p>Briefly, a custom value converter takes the following arguments:</p><ul><li><strong>source</strong> – the source JavaScript object for the bind operation</li><li><strong>sourceProperty</strong> – the name of the property to bind from the source JavaScript object</li><li><strong>dest</strong> – the destination DOM element for the bind operation</li><li><strong>destProperty</strong> – the name of the property to bind to the destination DOM element</li></ul><p>For this example we need to two converters: One that takes a string value and applies that as the transform attribute to an element of the SVG. The other takes a color as input and updates the style.fill value of the element to “tint” or “colorize” the element.</p><p>The code below defines the two custom converters, making them available on the SVGDemo “namespace” object:</p><pre class="code"><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">SVGDemo;
(</span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">(SVGDemo) {
    </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">Converters = (</span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">() {
        </span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">Converters() { }
        Converters.svgAttr = WinJS.Binding.initializer(</span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">(source, sourceProperty, dest, destProperty) {
            dest.setAttributeNS(</span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">, destProperty[0], source[sourceProperty[0]]);
        });
        Converters.tintColor = WinJS.Binding.initializer(</span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">(source, sourceProperty, dest, destProperty) {
            </span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">getR(color) {
                </span><span style="background: white; color: blue;">return </span><span style="background: white; color: black;">parseInt(color.substring(1, 3), 16);
            }
            </span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">getG(color) {
                </span><span style="background: white; color: blue;">return </span><span style="background: white; color: black;">parseInt(color.substring(3, 5), 16);
            }
            </span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">getB(color) {
                </span><span style="background: white; color: blue;">return </span><span style="background: white; color: black;">parseInt(color.substring(5, 7), 16);
            }
            </span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">hex(num) {
                </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">str = num.toString(16);
                </span><span style="background: white; color: blue;">if </span><span style="background: white; color: black;">(str.length == 1) {
                    </span><span style="background: white; color: blue;">return </span><span style="background: white; color: rgb(163, 21, 21);">'0' </span><span style="background: white; color: black;">+ str;
                }
                </span><span style="background: white; color: blue;">return </span><span style="background: white; color: black;">str;
            }
            </span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">scaleColor(factor, color) {
                </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">r = Math.floor(factor * getR(color));
                </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">g = Math.floor(factor * getG(color));
                </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">b = Math.floor(factor * getB(color));
                </span><span style="background: white; color: blue;">return </span><span style="background: white; color: rgb(163, 21, 21);">"#" </span><span style="background: white; color: black;">+ hex(r) + hex(g) + hex(b);
            }
            </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">color = dest[destProperty[0]][destProperty[1]];
            </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">tinted = scaleColor(getR(color) / 255, source[sourceProperty[0]]);
            dest[destProperty[0]][destProperty[1]] = tinted;
        });
    })();
    SVGDemo.Converters = Converters;
})(SVGDemo || (SVGDemo = {}));
</span></pre><p>&nbsp;</p><p>The first converter, <em>svgAttr</em> sets an attribute on the target SVG element. In this example:</p><pre class="code"><span style="background: white; color: blue;">&lt;</span><span style="background: white; color: maroon;">g </span><span style="background: white; color: red;">data-win-bind</span><span style="background: white; color: blue;">="transform:svgScale SVGDemo.Converters.svgAttr"&gt;</span></pre><pre class="code">&nbsp;</pre><p>The <em>transform</em> attribute of the element is set to the <em>.svgScale</em> member of the object to which the template is bound. And so if the input object to the binding operation looks like this:</p><pre class="code"><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">starYellow = {
       color: </span><span style="background: white; color: rgb(163, 21, 21);">"#FFFF00"</span><span style="background: white; color: black;">,
       svgScale: </span><span style="background: white; color: rgb(163, 21, 21);">"scale(1.0)"</span><span style="background: white; color: black;">,
       scale: 1.0
};

</span></pre><p>The <em>svgAttr</em> custom converter runs and the result is:</p><pre class="code"><span style="background: white; color: blue;">&lt;</span><span style="background: white; color: maroon;">g </span><span style="background: white; color: red;">transform</span><span style="background: white; color: blue;">="scale(1.0)"&gt;</span></pre><p>Custom converter <em>tintColor</em> is more sophisticated in that it takes both the bound object’s property into account, it also uses the original color of the targeted style property to help determine the final color. This converter uses the red component of the original style color to determine how much of the object’s source color to use. So the redder the template is, the more the source color is used; so that if the template’s color is pure red (#FF0000) then the resulting color is 100% of the source color.</p><p>So for example, we have a path with a <em>style.fill</em> we want to tint:</p><pre class="code"><span style="background: white; color: blue;">&lt;</span><span style="background: white; color: maroon;">path </span><span style="background: white; color: red;">style</span><span style="background: white; color: blue;">="</span><span style="background: white; color: red;">fill</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">#770000</span><span style="background: white; color: black;">;</span><span style="background: white; color: red;">fill-opacity</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">1</span><span style="background: white; color: black;">;</span><span style="background: white; color: red;">stroke</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">none</span><span style="background: white; color: black;">;</span><span style="background: white; color: blue;">"
   </span><span style="background: white; color: red;">d</span><span style="background: white; color: blue;">="m 483.39049,436.95746 …"
</span><span style="background: white; color: red;">   data-win-bind</span><span style="background: white; color: blue;">="style.fill:color SVGDemo.Converters.tintColor" &gt;
&lt;/</span><span style="background: white; color: maroon;">path</span><span style="background: white; color: blue;">&gt;
</span></pre><p>&nbsp;</p><p>Using the same <em>starYellow</em> object above, the converter evaluates the red value of the source template color and calculates the resulting color:</p><pre class="code"><span style="background: white; color: blue;">&lt;</span><span style="background: white; color: maroon;">path </span><span style="background: white; color: red;">style</span><span style="background: white; color: blue;">="</span><font style=""><font style="background-color: rgb(255, 255, 0);"><span style="background: white; color: red;">fill</span><span style="background: white; color: black;">:</span></font><font style="background-color: rgb(255, 255, 0);"><span style="background: white; color: blue;">#777700</span><span style="background: white; color: black;">;</span></font></font><span style="background: white; color: red;">fill-opacity</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">1</span><span style="background: white; color: black;">;</span><span style="background: white; color: red;">stroke</span><span style="background: white; color: black;">:</span><span style="background: white; color: blue;">none</span><span style="background: white; color: black;">;</span><span style="background: white; color: blue;">"
   </span><span style="background: white; color: red;">d</span><span style="background: white; color: blue;">="m 483.39049,436.95746 …"</span><span style="background: white; color: blue;">&gt;
&lt;/</span><span style="background: white; color: maroon;">path</span><span style="background: white; color: blue;">&gt;
</span></pre><p><strong>Note:</strong> This implementation of the <em>tintColor </em>converter assumes: 1) that you will be binding to <em>style </em>property 2) that property will be a <em>color</em>. </p><h2>Scaling SVG in the DOM</h2><p>SVG renders extremely well, but there may be issues getting it to flow properly in the document layout if you’ve scaled it like the code does above. Luckily, you have complete control over the DOM elements and if you know the size of the SVG that the template produces, you can easily calculate the size of the SVG when you render it.</p><pre class="code"><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">svgStarTemplateWidth = 329;
</span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">svgStarTemplateHeight = 326;

</span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">starTemplate = WinJS.Utilities.query(</span><span style="background: white; color: rgb(163, 21, 21);">"#starTemplate"</span><span style="background: white; color: black;">)[0].winControl;

</span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">renderStar(starInfo) {
    starTemplate.render(starInfo).then(</span><span style="background: white; color: blue;">function </span><span style="background: white; color: black;">(div) {
        div.style.width = (svgStarTemplateWidth * starInfo.scale) + </span><span style="background: white; color: rgb(163, 21, 21);">"px"</span><span style="background: white; color: black;">;
        div.style.height = (svgStarTemplateHeight * starInfo.scale) + </span><span style="background: white; color: rgb(163, 21, 21);">"px"</span><span style="background: white; color: black;">;
        div.style.display = </span><span style="background: white; color: rgb(163, 21, 21);">"inline-block"</span><span style="background: white; color: black;">;

        document.body.appendChild(div);
    });
}
</span></pre><p>Doing this allows the proper layout of elements on the page:</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/metablogapi/3034.image_74EEFCFF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-98-19-metablogapi/3034.image_5F00_74EEFCFF.png"><img width="71" height="244" title="image" style="display: inline; background-image: none;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/metablogapi/8233.image_thumb_3FE26DCF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-98-19-metablogapi/8233.image_5F00_thumb_5F00_3FE26DCF.png" border="0"></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/metablogapi/3527.image_38C33157.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-98-19-metablogapi/3527.image_5F00_38C33157.png"><img width="391" height="244" title="image" style="display: inline; background-image: none;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/metablogapi/0878.image_thumb_7482CA0A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-98-19-metablogapi/0878.image_5F00_thumb_5F00_7482CA0A.png" border="0"></a>&nbsp;</p><p>&nbsp;</p>  <h2>GIT the Code</h2><p>Download the code at <a title="https://github.com/gwsii/WinJSSVGTemplate" href="https://github.com/gwsii/WinJSSVGTemplate">https://github.com/gwsii/WinJSSVGTemplate</a></p><p>And be sure to download and enjoy your own copy of <a title="Windows Store - Gamer Dice" href="http://apps.microsoft.com/webpdp/en-US/app/gamer-dice/f414dc79-446b-44ca-9e73-240b14c3fda3" target="_blank">Gamer Dice</a> for Windows 8!</p>]]></content:encoded>
    </item>
    <item>
      <title>Basic text-based console UI implemented in F#</title>
      <link>https://docs.microsoft.com/archive/blogs/gsmith/basic-text-based-console-ui-implemented-in-f</link>
      <pubDate>Tue, 03 Jan 2012 23:36:00 GMT</pubDate>
      <dc:creator><![CDATA[Gregory W. Smith]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/gsmith/2012/01/03/basic-text-based-console-ui-implemented-in-f/</guid>
      <description><![CDATA[This is a brief exploration of some of the capabilities of the F# language to define a small set of...]]></description>
      <content:encoded><![CDATA[<p>This is a brief exploration of some of the capabilities of the F# language to define a small set of classes that can be leveraged to provide a simple text-based UI for an F# program. Example code is provided, which is a great introduction to the syntax, but a gentler and more thorough introduction to F# can be found at <a href="http://msdn.microsoft.com/en-us/library/dd233154.aspx" target="_blank">MSDN Visual F#</a>.</p>
<p>After learning more about the language from <a href="https://channel9.msdn.com/Blogs/David+Gristwood/An-Introduction-to-F-with-Don-Syme-1-of-4" target="_blank">a series of F# videos</a>, I decided to explore the language and tinker with it for a while. One of the first challenges a developer will face working with a new language is settling on a simple means to display results to the screen and get input from the user. F# can import .NET assemblies, which are certainly sufficient, but working on a basic text console it turned out to be an interesting way to explore the language. Admittedly, this is not a problem domain specifically suited for F#, but it exercises some of the fundamental capabilities of the language and is grounded in the familiar territory of the command line console.</p>
<h1></h1>
<h1>Box Console Text UI</h1>
<p>Here&rsquo;s a screenshot of what the final text console test program looks like, which renders its interface using the F# <em>BoxConsole</em> module.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/metablogapi/0412.image_060EAB1C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-98-19-metablogapi/0412.image_5F00_060EAB1C.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/metablogapi/4705.image_thumb_0C5581AA.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-98-19-metablogapi/4705.image_5F00_thumb_5F00_0C5581AA.png" width="817" height="404" /></a></p>
<p>Each of the boxes shown represents an instance of one of the classes defined in the <em>BoxConsole</em> module using structures to define the box location, size and style. The menu box in the center is an example of a <em>DosMenu</em> class which combines all of the building block classes to implement an F# application menu.</p>
<h2>F# Enumerations &amp; Simple Data Structures</h2>
<p>One of the fundamental affordances a programming language can provide is a mechanism to map enumerated integer values to a set of constant symbols, a.k.a. an Enumeration. F# employs it&rsquo;s pattern matching syntax to define an enumeration and here are some examples from the BoxConsole module:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e12b96c5-2d84-4fb3-a7ab-91ec30eee1cc" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">BoxConsole.fs</div>
<div style="background: #ddd; max-height: 500px; overflow: auto;"><ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;" start="17">
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Enumerates the four corners of a box.</span></li>
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">type</span> BoxCorner =</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;| UL = 0</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;| UR = 1</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;| LR = 2</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;| LL = 3</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li><span style="color: #008000;">// Enumerates possible text alignments.</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li><span style="color: #0000ff;">type</span> TextAlignment =</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;| Left = 0</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;| Center = 1</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;| Right = 2</li>
</ol></div>
</div>
</div>
<p>The first enumeration, <em>BoxCorner</em> expresses a shorthand to refer to the upper left, upper right, lower right and lower left corners of a box and the <em>TextAlignment</em> enumeration allows the users of the <em>BoxConsole</em> module to specify a left, center or right text justification.</p>
<h2></h2>
<p>Another fundamental programming language expression is the data record or structure that contains a collections of related values. The <em>BoxLocation</em> type defines a F# data structure to collect the data describing the size and position of a box.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:22b29362-d9e5-4ceb-b20a-5a7e0b9bb95a" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">BoxConsole.fs</div>
<div style="background: #ddd; overflow: auto;"><ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;" start="8">
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Contains box top, left, width and height information.</span></li>
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">type</span> BoxLocation =</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;{ Top : int;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Left : int;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Width : int;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Height : int; }</li>
</ol></div>
</div>
</div>
<p>The <em>BoxStyle</em> type describes the style of a <em>DosBox, </em>including members that describe the border style, margin around the text along with foreground and background colors of the box. In the case of the <em>BoxStyle</em> type, the <em>Border</em> member refers to an object and not a simple data type.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8d2230f5-08d9-43fd-92ec-4d67a567c2dc" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">BoxConsole.fs</div>
<div style="background: #ddd; overflow: auto;"><ol style="background: #ffffff; margin: 0 0 0 3em; padding: 0 0 0 5px;" start="241">
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Structure describing the syle of a DOS box.</span></li>
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">type</span> BoxStyle =</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;{ Border : BorderStyle;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Margin : int;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Foreground : System.ConsoleColor;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Background : System.ConsoleColor; }</li>
</ol></div>
</div>
</div>
<h2>&nbsp;</h2>
<h2>Mutable Values and Classes</h2>
<p>The &ldquo;immutable by default&rdquo; nature of F# encourages developers to craft code that the complier can optimize much more aggressively and runs faster in a parallel execution context. However, at the end of the day, the program must have a reasonable way to express it&rsquo;s state. The <em>mutable</em> keyword is the signal to F# that the variable being declared will be used in the more traditional manner: its value should be stored and can be expected to change during program execution. These mutable variables can then be used as fields to store values for the implementation of a class.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3587ec74-ec76-47fb-be1d-b3034ed039a6" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">BoxConsole.fs</div>
<div style="background: #ddd; overflow: auto;"><ol style="background: #ffffff; margin: 0 0 0 3em; padding: 0 0 0 5px;" start="174">
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Implements various styles for drawing boxes.</span></li>
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">type</span> BorderStyle = <span style="color: #0000ff;">class</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Defines a number of text patterns used to style the boxes. Each pattern is</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">//&nbsp;&nbsp;&nbsp;nine chracters in length and define the corner, edge and background characters.</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">member</span> <span style="color: #0000ff;">private</span> boxPatterns =</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #800000;">@"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/-\\-/|.|&nbsp;&nbsp;&nbsp;"</span> +</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #800000;">@"*-**-*| |+-++-+| | +++++++ +******* *////////////////\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"</span> +</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #800000;">@"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"</span> +</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #800000;">@"======&nbsp;&nbsp;&nbsp;vvv^^^&nbsp;&nbsp;&nbsp;~~~~~~) (XXXXXXX X +&nbsp;&nbsp;+ + +&nbsp;&nbsp;"</span> +</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #800000;">@" oooo uuu&nbsp;&nbsp;"</span></li>
<li style="background: #f3f3f3;">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Returns the specified set of nine-character box styles.</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">member</span> <span style="color: #0000ff;">private</span> getPattern n =</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">new</span> String [| <span style="color: #0000ff;">for</span> i <span style="color: #0000ff;">in</span> 0 .. 8 <span style="color: #0000ff;">-&gt;</span> BorderStyle.boxPatterns.[9*n + i] |]</li>
<li style="background: #f3f3f3;">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Determine start, middle or end style character for line of a specific size.</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">member</span> <span style="color: #0000ff;">private</span> boxPart size n =</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">match</span> n <span style="color: #0000ff;">with</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">-&gt;</span> 0</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| n <span style="color: #0000ff;">when</span> n = size <span style="color: #0000ff;">-&gt;</span> 2</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| _&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">-&gt;</span> 1</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Given a box style pattern, render a box of the specified size.</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">member</span> BoxLines(width : int, height : int, pattern : string) =</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ <span style="color: #0000ff;">for</span> h <span style="color: #0000ff;">in</span> [1..height] <span style="color: #0000ff;">-&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">new</span> System.String</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[| <span style="color: #0000ff;">for</span> w <span style="color: #0000ff;">in</span> 1 .. width <span style="color: #0000ff;">-&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">match</span> h, (BorderStyle.boxPart width w) <span style="color: #0000ff;">with</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 1, i&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">-&gt;</span> pattern.[i]</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| _, i <span style="color: #0000ff;">when</span> h = height <span style="color: #0000ff;">-&gt;</span> pattern.[i + 3]</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| _, i&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">-&gt;</span> pattern.[i + 6] |] ]</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Pattern in use for this border style.</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">val</span> <span style="color: #0000ff;">mutable</span> Pattern : string;</li>
<li style="background: #f3f3f3;">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Constructor to use one of the predefined style patterns.</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">new</span> (style: int) <span style="color: #0000ff;">as</span> border =</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ Pattern = <span style="color: #800000;">"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"</span>; }</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">then</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">if</span> style &lt;= BorderStyle.boxPatterns.Length / 9</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">then</span> border.Pattern &lt;- (BorderStyle.getPattern style)</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Constructor to use a custom nine-character style pattern.</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">new</span> (pattern : string) <span style="color: #0000ff;">as</span> border =</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ Pattern = <span style="color: #800000;">"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"</span>; }</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">then</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">if</span> pattern.Length &gt;= 9 <span style="color: #0000ff;">then</span> border.Pattern &lt;- pattern</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">end</span></li>
</ol></div>
</div>
</div>
<p><span style="font-size: xx-small;" size="1">(Note: Due to encoding issues, the contents of <em>boxPatterns</em> are not correctly rendered above. To see the complete set of character used, please download the <strong><em><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/projects/2234.FConsoleUI.zip" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-98-19-projects/2234.FConsoleUI.zip" target="_blank"><span style="text-decoration: underline;">project source code</span></a></em></strong>.)</span></p>
<p>Those new to F# but familiar with today&rsquo;s object-oriented patterns should be able to recognize those patterns peeking through this alien code if they &ldquo;squint&rdquo; just a little bit. The <em>static</em> keyword is used to express functionality within the class scope, and is omitted for instance members of a class. Creation of objects is achieved via the <em>new</em> keyword, which also used to declare class constructors. Also notice the use of the <em>private</em> keyword allowing the developer to control the visibility of members in order to help maintain encapsulation.</p>
<p>The <em>BorderStyle </em>class knows how to render a nine character array as a the corners and edges of a box. One constructor uses a predefined style and the other allows the caller to specify a custom set of nine characters to define a border style. This class is effectively implemented with a couple pattern matching methods.</p>
<p>The first, <em>boxPart</em>, matches determines which offset to use to (0-2) depending on if it&rsquo;s the first item in the list (yields 0), the last item in the list (2), or any other item in the list (1). Similar matching rules are employed in the <em>BoxLines<strong> </strong></em>function, but that pattern is wrapped in an array <strong>[| for w in 1 .. width &ndash;&gt; |]</strong> generated from a list <strong>[ for h in [1..height] &ndash;&gt; ]</strong>. Together, these two functions provide the character patterns for the box&rsquo;s border style given a width and height.</p>
<h2>Using the System.Console class</h2>
<p>Class <em>ConsoleUI </em>wraps the System.Console class for the <em>BoxConsole</em> module, making the console easier to use from the F# implementation. F# uses the <em>open </em>keyword to import other type libraries into the current program scope. In this case we import the System .NET module on line six, right after we explicitly declare the name of our module on line four.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:59f5ef90-2f7b-4edf-b491-8d01ef8c7925" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">BoxConsole.fs</div>
<div style="background: #ddd; overflow: auto;"><ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;" start="1">
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// BoxConsole.fs - Basic text-based console UI implemented in F#</span></li>
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">module</span> BoxConsole</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">open</span> System</li>
</ol></div>
</div>
</div>
<p>Taking a closer look at one of the <em>ConsoleUI</em> methods reveals how .NET methods and properties can be called from an F# application. The <em>WriteAt</em> function will write a message on the console in the requested location and will trim the message to prevent the console screen from scrolling.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bda1789d-16db-4bc9-9991-ff1f120a26ff" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">BoxConsole.fs</div>
<div style="background: #ddd; overflow: auto;"><ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;" start="40">
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Writes the message at the given location. This method will trim the message </span></li>
<li><span style="color: #008000;">//&nbsp;&nbsp;&nbsp;to pervent scrolling of the console window.</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">member</span> WriteAt message left top =</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">let</span> oleft = System.Console.CursorLeft</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">let</span> otop = System.Console.CursorTop</li>
<li style="background: #f3f3f3;">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">let</span> message = ConsoleUI.trimToPreventOverflow(message, left, top)</li>
<li style="background: #f3f3f3;">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;Console.CursorLeft &lt;- left</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;Console.CursorTop &lt;- top</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;Console.Write(message : string)</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;Console.CursorLeft &lt;- oleft</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;Console.CursorTop &lt;- otop</li>
</ol></div>
</div>
</div>
<p>Note the use of the variables <em>oleft</em> and <em>otop</em> which are used to store the current cursor position so it can be restored once the message is written. These variables are written to once and never modified. They are given their values using the <em>let </em>keyword and the equals (=) sign and they are immutable, the valu<em>e</em> is <span style="text-decoration: underline;">bound</span> that that name. Even in the case of <em>message,</em> the value is is not mutable: the old value of <em>message </em>is lost and a new one (possibly shorter) is created.</p>
<p>On the other hand, the .NET system <strong>Console.CursorLeft</strong> property is not immutable and must be modified to change the cursor position. In this case F# considers the variable mutable and allows its value to be changed using the <strong>&lt;-</strong> operator. Finally, the <em>WriteAt</em> function provides an example of calling a method on a .NET class, writing the message to the console using the <strong>Console.Write(message: string)</strong> syntax to invoke the method.</p>
<h1>Example Program</h1>
<p><strong>Program.fs</strong> is provided as a practical example of how to use the <em>BoxConsole</em> module to display and process user selections using the <em>DosMenu</em> class, and allows the user to cycle through some of the various styles and options available.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:009012d8-7bee-4250-bb66-657e0a116820" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Program.fs</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;" start="1">
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Program.fs - Console UI Test Application</span></li>
<li><span style="color: #008000;">///////////////////////////////////////////////////////////////////////////////</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">module</span> Program</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">open</span> BoxConsole</li>
<li><span style="color: #0000ff;">open</span> System</li>
<li style="background: #f3f3f3;">&nbsp;</li>
<li><span style="color: #008000;">// Define a menu to drive the program</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">let</span> m = DosMenu([<span style="color: #800000;">"Color"</span>; <span style="color: #800000;">"Style"</span>; <span style="color: #800000;">"Singleline"</span>; <span style="color: #800000;">"Multiline"</span>; <span style="color: #800000;">"Align"</span>; <span style="color: #800000;">"Margin"</span>; <span style="color: #800000;">"Quit"</span>], 3)</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Collections of colors to use for foreground and background testing</span></li>
<li><span style="color: #0000ff;">let</span> bgcs = [ ConsoleColor.DarkBlue; ConsoleColor.DarkMagenta; ConsoleColor.DarkRed; ConsoleColor.DarkGray; ConsoleColor.Black ]</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">let</span> fgcs = [ ConsoleColor.Yellow;&nbsp;&nbsp;&nbsp;ConsoleColor.Magenta;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ConsoleColor.Red;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ConsoleColor.White;&nbsp;&nbsp;&nbsp;&nbsp;ConsoleColor.White ]</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">Console.Clear()</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">let</span> <span style="color: #0000ff;">mutable</span> color = 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Currently selected color</span></li>
<li><span style="color: #0000ff;">let</span> <span style="color: #0000ff;">mutable</span> style = 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Currently selected style</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">let</span> <span style="color: #0000ff;">mutable</span> singleline = <span style="color: #0000ff;">true</span> <span style="color: #008000;">// Single line/multi-line text</span></li>
<li><span style="color: #0000ff;">let</span> <span style="color: #0000ff;">mutable</span> displayText = []&nbsp;&nbsp;<span style="color: #008000;">// Currently displayed text</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">let</span> <span style="color: #0000ff;">mutable</span> align = 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Currently selected text alignment</span></li>
<li><span style="color: #0000ff;">let</span> <span style="color: #0000ff;">mutable</span> margin = 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Currently selected style margin</span></li>
<li style="background: #f3f3f3;">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">let</span> <span style="color: #0000ff;">mutable</span> selection = <span style="color: #800000;">""</span><span style="color: #008000;">// User menu selection</span></li>
<li style="background: #f3f3f3;">&nbsp;</li>
<li><span style="color: #008000;">// Create a text box to contain current date / time, center horizontally.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">let</span> timeBox = <span style="color: #0000ff;">new</span> DosBox([System.DateTime.Now.ToLongTimeString(); System.DateTime.Now.ToLongDateString(); ])</li>
<li>timeBox.Location &lt;- { Top = Console.WindowHeight - 5; Left = timeBox.Location.Left; Width = timeBox.Location.Width + 2; Height = timeBox.Location.Height }</li>
<li style="background: #f3f3f3;">timeBox.BoxText.Align &lt;- TextAlignment.Center</li>
<li>timeBox.BoxText.Foreground &lt;- ConsoleColor.Green;</li>
<li style="background: #f3f3f3;">timeBox.BoxText.Background &lt;- ConsoleColor.DarkGreen;</li>
<li>timeBox.Style &lt;- { Border = <span style="color: #0000ff;">new</span> BorderStyle(3); Foreground = ConsoleColor.Green; Background = ConsoleColor.DarkGreen; Margin = 1; }</li>
<li style="background: #f3f3f3;">&nbsp;</li>
<li><span style="color: #008000;">// Main program loop</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">while</span> selection &lt;&gt; <span style="color: #800000;">"Quit"</span> <span style="color: #0000ff;">do</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Check if user made a valid selection</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">if</span> selection &lt;&gt; <span style="color: #800000;">""</span> <span style="color: #0000ff;">then</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.Clear()</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Update current state based on the user's selection</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">match</span> selection <span style="color: #0000ff;">with</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| <span style="color: #800000;">"Color"</span> <span style="color: #0000ff;">-&gt;</span> color &lt;- color + 1</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| <span style="color: #800000;">"Style"</span> <span style="color: #0000ff;">-&gt;</span> style &lt;- style + 1</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| <span style="color: #800000;">"Singleline"</span> <span style="color: #0000ff;">-&gt;</span> singleline &lt;- <span style="color: #0000ff;">true</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| <span style="color: #800000;">"Multiline"</span> <span style="color: #0000ff;">-&gt;</span> singleline &lt;- <span style="color: #0000ff;">false</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| <span style="color: #800000;">"Align"</span> <span style="color: #0000ff;">-&gt;</span> align &lt;- align + 1</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| <span style="color: #800000;">"Margin"</span> <span style="color: #0000ff;">-&gt;</span> margin &lt;- margin + 1</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| _ <span style="color: #0000ff;">-&gt;</span> ()</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Update each of the corner boxes</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">for</span> x <span style="color: #0000ff;">in</span> (int BoxCorner.UL)..(int BoxCorner.LL) <span style="color: #0000ff;">do</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">let</span> k = (x+color)%5</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Choose single line or multi-line text</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">let</span> cornerDisplay =</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">if</span> singleline <span style="color: #0000ff;">then</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayText &lt;- [selection]</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">else</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayText &lt;- [<span style="color: #800000;">"---------------"</span>; selection; <span style="color: #800000;">"---------------"</span>;]</li>
<li style="background: #f3f3f3;">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Create the box in the appropriate corner</span></li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">let</span> box = <span style="color: #0000ff;">new</span> DosCornerBox(displayText,enum&lt;BoxCorner&gt;(x))</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;box.Style &lt;- { Border = <span style="color: #0000ff;">new</span> BorderStyle (style%35); Foreground = fgcs.[k]; Background = bgcs.[k]; Margin = (margin % 4 + 1); }</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;box.BoxText.Foreground &lt;- fgcs.[k]</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;box.BoxText.Background &lt;- bgcs.[k]</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;box.BoxText.Align &lt;- enum&lt;TextAlignment&gt;((int align) % 3)</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;box.RecalcBox()</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;box.Draw()</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Select current foreground/background color combination</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">let</span> v = (color+4)%5</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;m.Style &lt;- { Border = <span style="color: #0000ff;">new</span> BorderStyle (style%35); Foreground = fgcs.[v]; Background = bgcs.[v]; Margin = (margin % 5); }</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;m.Box.BoxText.Foreground &lt;- fgcs.[v]</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;m.Box.BoxText.Background &lt;- bgcs.[v]</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Update the current date and time</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;timeBox.BoxText.Text &lt;- [System.DateTime.Now.ToLongTimeString(); System.DateTime.Now.ToLongDateString(); ]</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;timeBox.Draw()</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">// Wait for user selection, or timeout in 1s</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;selection &lt;- m.GetSelectionTimeout 1000</li>
<li style="background: #f3f3f3;">&nbsp;&nbsp;&nbsp;&nbsp;()</li>
</ol></div>
</div>
</div>
<p>The example first declares the module name and imports the <strong>System</strong> and <strong>BoxConsole</strong> types. The program then creates the <em>DosMenu</em> containing a list of the box styles through which the user can cycle. Next the program declares a set of working variables. It&rsquo;s interesting to note that like many other program there is a mix of immutable and mutable variables, but in F# it&rsquo;s mutable variables that are the exception that require additional semantic notation.</p>
<p>Next the program creates a <em>DosBox</em> that displays the time and then enters the main program while loop where it will run until the user selects &ldquo;Quit&rdquo;. In the body of the main loop, if the user has made a selection then the program options are updated. Finally, the program will pause for 1000ms to wait for the user&rsquo;s next selection from the <em>DosMenu</em>.</p>
<p>Download <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/projects/2234.FConsoleUI.zip" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-98-19-projects/2234.FConsoleUI.zip" target="_blank">complete BoxConsole source code</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>Animation with the HTML Canvas Tag and the IE9 Preview in Expression Web 4</title>
      <link>https://docs.microsoft.com/archive/blogs/gsmith/animation-with-the-html-canvas-tag-and-the-ie9-preview-in-expression-web-4</link>
      <pubDate>Thu, 19 Aug 2010 22:25:00 GMT</pubDate>
      <dc:creator><![CDATA[Gregory W. Smith]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/gsmith/2010/08/19/animation-with-the-html-canvas-tag-and-the-ie9-preview-in-expression-web-4/</guid>
      <description><![CDATA[In this post I will walk through the steps necessary to create basic animation using the HTML canvas...]]></description>
      <content:encoded><![CDATA[<p><span style="font-size: small;"><span style="font-family: Calibri;">In this post I will walk through the steps necessary to create basic animation using the HTML canvas element, some of the capabilities of the canvas context and how to configure <a href="http://www.microsoft.com/expression/products/Web_Overview.aspx">Expression Web 4</a> to preview with the IE9 Platform Preview.</span></span></p>
<p><span style="font-family: Calibri; font-size: small;">The HTML canvas element has been available and implemented in most browsers for years now and is going to be implemented in the </span><a href="http://ie.microsoft.com/testdrive/"><span style="font-family: Calibri; color: #0000ff; font-size: small;">Internet Explorer 9 Platform Preview</span></a><span style="font-size: small;"><span style="font-family: Calibri;"> (IE9). And with the new focus on the creation of Rich Internet Applications (RIAs) using HTML 5, CSS3 and JavaScript the canvas element is going to become a lot more useful.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;"></span></span><span style="font-size: small;"><span style="font-family: Calibri;">The canvas element provides a location in an HTML document with the web page author can draw shapes and text using JavaScript.<span style="mso-spacerun: yes;">&nbsp; </span>Because authors can control what is drawn exactly, the canvas element provides pixel perfect rendering of what needs to be displayed. </span></span><span style="font-size: small;"><span style="font-family: Calibri;">Drawing on the canvas element in JavaScript is performed through a proxy object called a context.<span style="mso-spacerun: yes;">&nbsp; </span>The context allows you to draw on the canvas element using X and Y coordinates, and setting things like line styles and colors.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;">First, declare the canvas element in your HTML markup.</span></span></p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/4682.bubbles_1.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/4682.bubbles_5F00_1.png" alt="The canvas element declared in the page markup" /><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />Then, when the animation starts a context is created which is then used to draw on the canvas.<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"><v:shape o:spid="_x0000_i1036" type="#_x0000_t75" id="Picture_x0020_2" style="width: 468pt; height: 170.25pt; visibility: visible;"><v:imagedata src="file:///C:\Users\Gregory\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png"><span style="font-family: Calibri; font-size: small;"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/3000.bubbles_2.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/3000.bubbles_5F00_2.png" alt="Getting the canvas element and a context" /></span></v:imagedata></v:shape></span><o:p></o:p><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />Now that the context has been created it may be used to perform basic drawing.<span style="mso-spacerun: yes;">&nbsp; </span>To draw a rectangle, first enter line style and color on the context, then call strokeRect() or fillRect() to draw the rectangle.<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"></span><o:p></o:p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/3343.bubbles_13.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/3343.bubbles_5F00_13.png" alt="Using fillRect()" height="35" width="470" /><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />The context is used to control more than just the color used with the wind style used; it also allows control over opacity using the globalAlpha property.<span style="mso-spacerun: yes;">&nbsp; </span>And when drawing text, the context may be used to control the font and text alignment.<span style="mso-spacerun: yes;">&nbsp; </span>Once the settings are made on the context, calling field text or stroke text draws the text on the canvas.<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"></span><o:p></o:p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/6305.bubbles_3.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/6305.bubbles_5F00_3.png" alt="Using the globalAlpha and text context properties" /><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />Other effects include gradients, both linear and radial, where you can define your own custom color stops.<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"></span><o:p></o:p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/6305.bubbles_4.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/6305.bubbles_5F00_4.png" alt="Using a linear gradient" /><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />Now that we know how to do basic drawing on the canvas using the context object, we can create an animation effect by drawing slightly different images over time.<span style="mso-spacerun: yes;">&nbsp; </span>Using the JavaScript setTimeout() function, we can create an animation loop:<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"></span><o:p></o:p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/4130.bubbles_5.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/4130.bubbles_5F00_5.png" alt="Using setTimeout to create an animation loop" /><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />The function above is called every 50 milliseconds, and invokes the render() function which does the work a drawing the each frame.<span style="mso-spacerun: yes;">&nbsp; </span>By making small changes from one frame to the next we can create the illusion of motion. <o:p></o:p></span></span><br /><span style="font-size: small;"><span style="font-family: Calibri;">Because the canvas element doesn&rsquo;t remember anything about what we have drawn on it before, we keep track of what we want to draw in JavaScript and erase the entire canvas before we draw each frame. Traditionally in computer animation, elements that represent graphical objects on the screen are referred to as sprites.<span style="mso-spacerun: yes;">&nbsp;<br /></span></span></span><br /><span style="font-size: small;"><span style="font-family: Calibri;">JavaScript objects can support the basic properties needed to implement a sprite: an X and Y position with a width and height.<span style="mso-spacerun: yes;">&nbsp; </span>For animation purposes we also want to include information about the objects movement along the X and Y axis, which are DX and DY in the code below.<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"></span><o:p></o:p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/3225.bubbles_6.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/3225.bubbles_5F00_6.png" alt="Defining a Sprite class in Javascript to track animation data" /><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />For my animation, I wanted to show bubbles floating up from the bottom of the canvas.<span style="mso-spacerun: yes;">&nbsp; </span>So using JavaScript I was able to extend the sprites functionality to draw my bubbles.<span style="mso-spacerun: yes;">&nbsp; </span>Notice how I define bubble to have a color associated with it and I overwrite the animate function to use that color when drawing the bubble.<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"></span><o:p></o:p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/5488.bubbles_7.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/5488.bubbles_5F00_7.png" alt="Extending the Sprite class to make a Bubble" /><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />To keep track of all of the bubbles that we will be animating, we create an array called allBubbles were a place the new bubbles as they are created. Each bubble we make is given a random location, green color and vertical motion then added to the array.<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"></span><o:p></o:p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/4718.bubbles_8.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/4718.bubbles_5F00_8.png" alt="Initializing the Bubbles" /><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />For the text and the background gradient, it&rsquo;s not necessary to use JavaScript objects to keep track of their state, so they can be drawn by themselves <br />inside of the render loop for simplicity.<span style="mso-spacerun: yes;">&nbsp; </span>For a little more pizzazz I am also animating the gradient using a simple sine wave.<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"></span><o:p></o:p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/8015.bubbles_9.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/8015.bubbles_5F00_9.png" alt="Animating a linear gradient by offsetting the middle color stop" /><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />Here&rsquo;s the final version of my page containing the gratuitous canvas animation.<span style="mso-spacerun: yes;">&nbsp; </span>I developed this example using Expression Web 4 and tested it in Firefox, Opera, Chrome and Safari.<span style="mso-spacerun: yes;">&nbsp; </span>These browsers have had longstanding support for the canvas element and my example works well.<o:p></o:p></span></span></p>
<div style="font-family: Consolas; Courier New; font-size: 10pt; color: black; background: white;"><span style="color: blue;"></span></div>
<div style="font-family: Consolas; Courier New; font-size: 10pt; color: black; background: white;"><span style="color: blue;">&lt;!</span><span style="color: #a31515;">DOCTYPE</span> <span style="color: red;">html</span><span style="color: blue;">&gt;</span><br /><span style="color: blue;">&lt;</span><span style="color: #a31515;">html</span><span style="color: blue;">&gt;</span><br />&nbsp; <span style="color: blue;">&lt;</span><span style="color: #a31515;">head</span><span style="color: blue;">&gt;</span><br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">&lt;</span><span style="color: #a31515;">meta</span> <span style="color: red;">content</span><span style="color: blue;">="text/html; charset=utf-8"</span> <span style="color: red;">http-equiv</span><span style="color: blue;">="Content-Type"&gt;</span><br />&nbsp;<br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">&lt;</span><span style="color: #a31515;">style</span> <span style="color: red;">type</span><span style="color: blue;">="text/css"</span> <span style="color: blue;">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #a31515;">canvas</span> { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: red;">background-color</span>:<span style="color: blue;">black</span>;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">&lt;/</span><span style="color: #a31515;">style</span><span style="color: blue;">&gt;</span><br />&nbsp;<br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">&lt;</span><span style="color: #a31515;">script</span> <span style="color: red;">type</span><span style="color: blue;">="text/javascript"</span> <span style="color: blue;">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> canvasWidth = 500;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> canvasHeight = 300;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> canvas;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> dc2d;&nbsp; <br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green;">// Define a basic sprite class</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">function</span> Sprite(context, x, y, width, height)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.context = context;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.x = x;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.y = y;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.width = width;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.height = height;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.dx = 0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.dy = 0;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.Animate = <span style="color: blue;">function</span>() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.x = x + dx;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.y = y + dy;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.context.strokeRect(x,y,width,height);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green;">// Extend the sprite class to make a bubble class</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">function</span> Bubble(context, x, y, width, height, r, g, b)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.baseClass = Sprite;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.baseClass(context, x, y, width, height);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.maxy = 0;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.fillStyle = <span style="color: #a31515;">"rgb("</span> + r + <span style="color: #a31515;">","</span> + g + <span style="color: #a31515;">","</span> + b + <span style="color: #a31515;">")"</span>;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.Animate = <span style="color: blue;">function</span>()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.y = <span style="color: blue;">this</span>.y + <span style="color: blue;">this</span>.dy;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span>( <span style="color: blue;">this</span>.y &lt; 0 ) <span style="color: blue;">this</span>.y = <span style="color: blue;">this</span>.maxy;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.context.fillStyle = <span style="color: blue;">this</span>.fillStyle;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">this</span>.context.fillRect( <span style="color: blue;">this</span>.x, <span style="color: blue;">this</span>.y, <span style="color: blue;">this</span>.width, <span style="color: blue;">this</span>.height);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green;">// Main animation loop.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">function</span> animationLoop()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; render();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setTimeout(<span style="color: #a31515;">"animationLoop()"</span>, 50);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> theta = 0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> angle = Math.PI / 1028;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green;">// Draws a single frame on the canvas&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">function</span> render()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; theta = theta + angle;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span>( theta &gt; 2 * Math.PI ) theta = theta - 2 * Math.PI; <br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dc2d.clearRect(0, 0, 500, 300);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> sine = Math.sin(theta);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> gradient = dc2d.createLinearGradient(200,0,300,300);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gradient.addColorStop(0,<span style="color: #a31515;">"rgb(0,64,0)"</span>);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gradient.addColorStop(0.25*sine+0.5,<span style="color: #a31515;">"rgb(0,0,0)"</span>);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gradient.addColorStop(1,<span style="color: #a31515;">"rgb(16,32,16)"</span>);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dc2d.fillStyle = gradient;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dc2d.fillRect(0,0,500,300);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">for</span>( <span style="color: blue;">var</span> i = 0; i &lt; bubbleCount; i++ )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; allBubbles[i].Animate();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dc2d.fillStyle = <span style="color: #a31515;">"rgb(0,255,0)"</span>;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dc2d.font = <span style="color: #a31515;">"50px sans-serif"</span>;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dc2d.textAlign = <span style="color: #a31515;">"center"</span>;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dc2d.globalAlpha = 0.5;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dc2d.fillText( <span style="color: #a31515;">"Microsoft"</span>, 250, 125 );<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dc2d.fillText( <span style="color: #a31515;">"Expression Web"</span>, 250, 175 );<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dc2d.globalAlpha = 1.0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green;">// Gets the canvas and 2D context&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">function</span> getCanvas()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; canvas = document.getElementById(<span style="color: #a31515;">"canvas1"</span>);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span>( canvas )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dc2d = canvas.getContext(<span style="color: #a31515;">"2d"</span>);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">else</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(<span style="color: #a31515;">"Failed to get canvas element"</span>);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span>;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> allBubbles;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> bubbleCount = 250;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green;">// Create all the bubbles we want to animate</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">function</span> createBubbles()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; allBubbles = <span style="color: blue;">new</span> Array();<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">for</span>( <span style="color: blue;">var</span> i = 0; i &lt; bubbleCount; i++ )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> width = Math.random() * 1 + Math.random() * 1 + 1;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> height = width;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> startPosX = Math.random() * (canvasWidth - width - 1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> startPosY = Math.random() * (canvasHeight - height - 1);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> deltaX = 0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> deltaY = -5 * Math.random() - 2.5;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> g = Math.floor( 128 * Math.random() + 127 );&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> r = Math.floor( 128 * Math.random() );<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> ( r &gt; g ) r = g;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> b = r;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> bubble = <span style="color: blue;">new</span> Bubble(dc2d, startPosX, startPosY, width, height, r, g, b);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bubble.dx = deltaX;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bubble.dy = deltaY;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bubble.maxy = 300;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; allBubbles[i] = bubble;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green;">// Starts the animation for the canvas</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">function</span> startAnimation()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getCanvas();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; createBubbles();<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; animationLoop();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">&lt;/</span><span style="color: #a31515;">script</span><span style="color: blue;">&gt;</span><br />&nbsp; <span style="color: blue;">&lt;/</span><span style="color: #a31515;">head</span><span style="color: blue;">&gt;</span><br />&nbsp; <span style="color: blue;">&lt;</span><span style="color: #a31515;">body</span><span style="color: blue;">&gt;</span><br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">&lt;</span><span style="color: #a31515;">canvas</span> <span style="color: red;">width</span><span style="color: blue;">="500"</span> <span style="color: red;">height</span><span style="color: blue;">="300"</span> <span style="color: red;">id</span><span style="color: blue;">="canvas1"&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Your browser does not support the CANVAS tag. Sorry!<br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">&lt;/</span><span style="color: #a31515;">canvas</span><span style="color: blue;">&gt;</span><br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">&lt;</span><span style="color: #a31515;">br</span><span style="color: blue;">&gt;</span><br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">&lt;</span><span style="color: #a31515;">button</span> <span style="color: red;">onclick</span><span style="color: blue;">="startAnimation()"</span> <span style="color: blue;">&gt;</span>Start Animation<span style="color: blue;">&lt;/</span><span style="color: #a31515;">button</span><span style="color: blue;">&gt;</span><br />&nbsp; <span style="color: blue;">&lt;/</span><span style="color: #a31515;">body</span><span style="color: blue;">&gt;</span><br /><span style="color: blue;">&lt;/</span><span style="color: #a31515;">html</span><span style="color: blue;">&gt;</span><br /></div>
<p><span style="font-size: small;"><span style="font-family: Calibri;"><br />The new Internet Explorer 9 Platform Preview also supports the canvas element, and you can configure Expression Web 4 to use IE9 preview as another browser in which you can preview a page.<span style="mso-spacerun: yes;">&nbsp; </span>From Expression Web, open the File menu, then select &ldquo;Preview in Browser&rdquo; then &ldquo;Edit the Browser List&hellip;&rdquo;<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"></span><o:p></o:p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/8816.bubbles_10.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/8816.bubbles_5F00_10.png" alt="Edit Browser List ..." /><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />In the Edit Browser List dialog click on the &ldquo;Add&hellip;&rdquo; button, browse for the IE 9 Platform Preview program (iepreview.exe), select it and make sure it&rsquo;s checked in the Edit Browser List window and click OK.<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"></span><o:p></o:p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/3617.bubbles_11.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/3617.bubbles_5F00_11.png" alt="Edit Browser List Dialog" /><br /><span style="font-size: small;"><span style="font-family: Calibri;"><br />Now you can setup Expression Web to launch the IE 9 just by clicking the Preview in Browser button (F12).<br /><o:p></o:p></span></span><br /><span style="mso-no-proof: yes;"></span><o:p></o:p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/98/19/0068.bubbles_12.png" original-url="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-98-19/0068.bubbles_5F00_12.png" alt="Bubbles in Internet Explorer 9 Platform Preview" /><br /><span style="font-family: Calibri; font-size: small;"><br />In this post we discussed how to perform basic drawing with the HTML canvas element and provided basic tips on animation.<span style="mso-spacerun: yes;">&nbsp; </span>I hope that you enjoyed this post and continue exploring the new capabilities in the IE 9 Platform Preview and using Expression Web 4.<span style="mso-spacerun: yes;">&nbsp; </span>I&rsquo;d like to thank John Allsopp for his great </span><a href="http://courses.sitepoint.com/html5-live"><span style="font-family: Calibri; font-size: small;">HTML 5 Live</span></a><span style="font-size: small;"><span style="font-family: Calibri;"> course at Sitepoint.com which provided my first introduction to the canvas element and many more HTML 5 features.<o:p></o:p></span></span></p>]]></content:encoded>
    </item>
    <item>
      <title>Web Fonts Simplified</title>
      <link>https://docs.microsoft.com/archive/blogs/gsmith/web-fonts-simplified</link>
      <pubDate>Mon, 09 Aug 2010 21:03:00 GMT</pubDate>
      <dc:creator><![CDATA[Gregory W. Smith]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/gsmith/2010/08/09/web-fonts-simplified/</guid>
      <description><![CDATA[Design and Typography go hand in hand. &nbsp;But every time I&rsquo;ve looked at using specific...]]></description>
      <content:encoded><![CDATA[<p><span style="font-size: small;"><span style="font-family: Calibri;">Design and Typography go hand in hand. <span style="mso-spacerun: yes;">&nbsp;</span>But every time I&rsquo;ve looked at using specific fonts with my web pages, it seemed confusing and difficult to get working. So many web page designers simply give up and wind up using text in the background images. There are a few problems with this approach, including accessibility and page content sematic issues. Sometimes pixel level control of the page rendering is necessary, but other times we want the browser and user to control the layout and display of text.<o:p></o:p></span></span></p>
<h1 style="margin: 24pt 0in 0pt;"><span style="color: #365f91;"><span style="font-family: Cambria;">Browser Support<o:p></o:p></span></span></h1>
<p><span style="font-size: small;"><span style="font-family: Calibri;">In this post I will briefly discuss web font support in browsers historically and today, the kinds of fonts used and how to work with them and how to consume them in the page markup.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;">Microsoft added embedded font support in first version of Internet Explorer with the FONT FACE tag in 1995, with versions 3, 4 and 5 adding support for CSS. Unfortunately, this support required the end user to have the requested font installed on their system. Microsoft eventually provided the WEFT tool to allow authors to embed fonts into their pages, allowing the user to view the page correctly without having the font installed. </span></span></p>
<p><span style="font-family: Calibri; font-size: small;">The font format supported by Internet Explorer is the </span><a href="http://en.wikipedia.org/wiki/Embedded_OpenType"><span style="font-family: Calibri; font-size: small;">Embedded Open Type</span></a><span style="font-family: Calibri; font-size: small;"> (EOT) file format, which never caught on with any of the other browsers. All the other browsers that I have checked (including the latest versions of Firefox, Chrome, Opera and Safari) all support the </span><a href="http://en.wikipedia.org/wiki/TrueType"><span style="font-family: Calibri; font-size: small;">TrueType</span></a><span style="font-size: small;"><span style="font-family: Calibri;"> (TTF) font format.<o:p></o:p></span></span></p>
<h1 style="margin: 24pt 0in 0pt;"><span style="color: #365f91;"><span style="font-family: Cambria;">Converting fonts<o:p></o:p></span></span></h1>
<p><span style="font-family: Calibri;"><span style="font-size: small;">Since most of the fonts I&rsquo;ve used on Windows are True Type fonts, and in order them to be used in Internet Explorer they have to be made available to users in the EOT format.<o:p></o:p></span></span></p>
<p><span style="font-family: Calibri; font-size: small;">Microsoft has historically provided the </span><a href="http://www.microsoft.com/typography/WEFT.mspx"><span style="font-family: Calibri; font-size: small;">Web Embedding Fonts Tool</span></a><span style="font-family: Calibri;"><span style="font-size: small;"> (WEFT) tool to help web page authors generate EOT. This is a full GUI that will scan the site and identify all characters from the site that the font will need to include and encodes those characters only and packages them into a EOT font format that can be uploaded to the server. I have used this tool and it&rsquo;s not easy or intuitive and didn&rsquo;t handle the font I was using.<o:p></o:p></span></span></p>
<p><span style="font-family: Calibri; font-size: small;">As an alternative, I have found an open source command-line utility </span><a href="http://code.google.com/p/ttf2eot/"><span style="font-family: Calibri; font-size: small;">ttf2eot</span></a><span style="font-family: Calibri;"><span style="font-size: small;"> (licensed under the GNU GPL v2) which has a Windows version that is available for download. This utility was originally developed for Unix systems so is a little different to use that typical Windows program. It takes the font to convert as the input stream and writes the converted font to the output stream. This just means that you run the command from the windows command line like this:<o:p></o:p></span></span></p>
<p><span style="font-family: Consolas;"><span style="font-size: small;">TTF2EOT &lt; MyFont.ttf &gt; MyFont.eot<o:p></o:p></span></span></p>
<h1 style="margin: 24pt 0in 0pt;"><span style="color: #365f91;"><span style="font-family: Cambria;">Using CSS @font-face<o:p></o:p></span></span></h1>
<p><span style="font-family: Calibri;"><span style="font-size: small;">Now that the font is available in both of the formats needed by the browsers, the page now needs to reference the font and consume it in markup.<o:p></o:p></span></span></p>
<p><span style="font-family: Calibri;"><span style="font-size: small;">The CSS code to allow all browsers to display the embedded font correctly is relatively simple. All that needs to be done is to include the @font-face declarations is the correct order so that all the browsers can pick up the appropriate font information.<o:p></o:p></span></span></p>
<p><span style="font-family: Consolas;"><span style="font-size: small;">&lt;style type="text/css"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @font-face { font-family: "Alien"; src: url(ElementalEnd.eot); }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @font-face { font-family: "Alien"; src: url(ElementalEnd.ttf); }&nbsp; <o:p></o:p></span></span></p>
<p><span style="font-family: Consolas;"><span style="font-size: small;">&lt;/style&gt;<o:p></o:p></span></span></p>
<p><span style="font-family: Calibri;"><span style="font-size: small;">Once the font-face has been declared it can now be consumed just like any other built in font.<o:p></o:p></span></span></p>
<p><span style="font-family: Consolas;"><span style="font-size: small;">&lt;html&gt;<br />&nbsp; &lt;head&gt;<br />&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: Consolas;"><span style="font-size: small;"><span style="font-family: Consolas;"><span style="font-size: small;">&lt;style type="text/css"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; h1 { font-family: "Alien"; }<br />&nbsp;&nbsp;&nbsp; &lt;/style&gt;<br />&nbsp; &lt;/head&gt;<br /></span></span>&nbsp; &lt;body&gt;<br /><span style="mso-tab-count: 1;">&nbsp;&nbsp;&nbsp; </span>&lt;h1&gt;My UFO Research Site&lt;/h1&gt;<br />&nbsp; &lt;/body&gt;<br />&lt;/html&gt;<o:p></o:p></span></span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;">That&rsquo;s all there is to it! Just make the font available in both formats and reference them both in correct order and you can style your page with them. <o:p></o:p></span></span></p>
<p><span style="mso-spacerun: yes;"><span style="font-family: Calibri; font-size: small;"></span></span></p>
<h1 style="margin: 24pt 0in 0pt;"><span style="color: #365f91;"><span style="font-family: Cambria;">Licensing Considerations</span></span></h1>
<p><span style="mso-spacerun: yes;"><span style="font-family: Calibri; font-size: small;"></span></span></p>
<p><span style="font-family: Calibri;"><span style="font-size: small;">Remember, you should only host and embed fonts&nbsp;for which&nbsp;you have the appropriate software licenses.</span></span></p>
<p><span style="mso-spacerun: yes;"><span style="font-family: Calibri; font-size: small;"></span></span></p>
<p>&nbsp;</p>
<p><span style="mso-spacerun: yes;"><span style="font-family: Calibri; font-size: small;"></span></span></p>
<div></div>
<p></p>]]></content:encoded>
    </item>
    <item>
      <title>Create a Font Reference Sheet for All Installed Fonts</title>
      <link>https://docs.microsoft.com/archive/blogs/gsmith/create-a-font-reference-sheet-for-all-installed-fonts</link>
      <pubDate>Wed, 27 Jan 2010 21:11:00 GMT</pubDate>
      <dc:creator><![CDATA[Gregory W. Smith]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/gsmith/2010/01/27/create-a-font-reference-sheet-for-all-installed-fonts/</guid>
      <description><![CDATA[I have always been crazy about typefaces and it's one of the things that attracts me to page design...]]></description>
      <content:encoded><![CDATA[<P>I have always been crazy about typefaces and it's one of the things that attracts me to page design and graphic illustration. Fonts come in so many variaties and variations, it's hard to remember which is which. Historically publishers of fonts and typefaces would print catalogues of sample text in various fonts so you could see what all the characters in each font looked like. This was a simple and relatively striaght-forward way to find a typeface you were looking for, or to browse for a font to use in your latest project.</P>
<P>A year or two back I came up with an idea to make a HTML page that displayed a number of my fonts with some sample text by using the style attribute for a paragraph to change the font-family to the font I wanted to preview. I was able to select the font I wanted from the few I slected when it occured to me that .NET supports accessing all the fonts installed on the system. It was a very quick and simple idea that allows the user to create a "Reference Sheet" of all typefaces installed on&nbsp;their local system.</P>
<P><IMG style="WIDTH: 574px; HEIGHT: 708px" title="Font Reference Sheet Preview" alt="Font Reference Sheet Preview" align=left src="http://www.gwsii.com/blog/fontref/iepreview.jpg" width=574 height=708 mce_src="http://www.gwsii.com/blog/fontref/iepreview.jpg"></P>
<P mce_keep="true">Now when I'm looking for inspiration for a new logo, or looking for just the right typeface to make that new website's design hang together perfectly, I have one page I can scroll through to see everything I have available. I really like just loading the page in a browser and paging through it. You can copy the text from the page and it will retain the font information, so you can paste it into Word or other editors which recognize the text's typeface info.</P>
<P>While I have cleaned up this version before I release it to the world, this little utility is pretty "low-tech" and not too friendly. I provide a reasonable set of defaults so the resulting Font Reference Sheet would include text to show a reasonable representation for a typical font. It's styled neatly with alternating white and light grey background to distinguish one font from the next. The name of each font is displayed in a plain Arial text so you can read the names for strange or symbol fonts.</P>
<P>The tool allows the user to select where to save and what to name the reference page. It allows the user to slect the text and background colors that the page will use to display the fonts, allowing the user to see the fonts used with different combinations of foreground and background colors. The user can also choose to alternate the sample text color or the background color or both.</P>
<P><IMG style="WIDTH: 750px; HEIGHT: 600px" title="Snapshot of the Font Reference Sheet  tool" alt="Snapshot of the Font Reference Sheet  tool" align=left src="http://www.gwsii.com/blog/fontref/appsnapshot.jpg" width=750 height=600 mce_src="http://www.gwsii.com/blog/fontref/appsnapshot.jpg"></P>
<P mce_keep="true">The user can change the entire page template or the font template so that they can include their own font sample text or change the page styles or layout. Color or font name values can be inserted by using special text, for the font template:</P>
<P><STRONG>[--font-family--]</STRONG> The family of the current font<BR><STRONG>[--color--]</STRONG> The current font text color<BR><STRONG>[--background-color--]</STRONG> The current font backgound color</P>
<P>Or for the page template:</P>
<P><STRONG>[--body--]</STRONG> Where to inject the font templates once processed<BR><STRONG>[--background-color--]</STRONG> Always the first font background color</P>
<P>Now this only works because the markup is specifically targeting the font faces it knows you have installed. Unless this page is viewed on a computer with all the same fonts installed, it won't render with the correct fonts. The purpose of this page is to provide the local user with text samples in fonts installed locally and viewed locally. This won't work if you server this page up via a web server, for example. Providing an end user with a custom font isn't something that is commonly supported yet.</P>
<P mce_keep="true">I've included the source code to the this tool, and while I hope it is useful I do not gaurantee it's usfulness or suitability for any specify application and by downloading the source code, the user agree to this stipulation.</P>
<P mce_keep="true">Download the project Visual Studio 2008 code here: <A href="http://www.gwsii.com/blog/fontref/fontreferencepage.zip">http://www.gwsii.com/blog/fontref/fontreferencepage.zip</A></P>]]></content:encoded>
    </item>
    <item>
      <title>Expression Web 3 / CSS Layout and Blog Makeover</title>
      <link>https://docs.microsoft.com/archive/blogs/gsmith/expression-web-3-css-layout-and-blog-makeover</link>
      <pubDate>Wed, 22 Jul 2009 13:00:00 GMT</pubDate>
      <dc:creator><![CDATA[Gregory W. Smith]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/gsmith/2009/07/22/expression-web-3-css-layout-and-blog-makeover/</guid>
      <description><![CDATA[As a member of the Microsoft Expression Web team,&nbsp;I am&nbsp;proud to&nbsp;be a part of&nbsp;our...]]></description>
      <content:encoded><![CDATA[<P>As a member of the <A title="Microsoft Expression" href="http://www.microsoft.com/expression/" target=_blank mce_href="http://www.microsoft.com/expression/">Microsoft Expression Web</A> team,&nbsp;I am&nbsp;proud to&nbsp;be a part of&nbsp;our newest release: Microsoft Expression Web 3.&nbsp;Not only am I&nbsp;pleased and very grateful to have had an opportunity to contribute to the release of this application, I am also looking forward to using Expression Web as the&nbsp;finest tool to edit and design amazing websites.</P>
<P>Expression Web is the&nbsp;perfect tool for people who design websites and allows users&nbsp;create CSS that works exactly the way it should,&nbsp;which makes&nbsp;it poised to be the web designer's tool of choice for standards base web design and layout. I have some <SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">experience</SPAN> in using CSS for simple text&nbsp;styling and basic page look and feel, however, this only scratches the surface of the power of CSS and I want to learn more.</P>
<P>My ultimate goal is to produce a CSS sheet that will be considered for the <A title="CSS Zen Garden" href="http://www.csszengarden.com/" target=_blank mce_href="http://www.csszengarden.com/">CSS Zen Garden</A>. If you're a student of CSS and you've not had a chance to see the Zen Garden, I encourage you to look at what this site revels about the power and flexibility of CSS. If anything, these examples show that I have a lot more to learn about CSS and how to use it for layout and full page customization.</P>
<P>Learning more about CSS will involve a number of projects, starting with the "re-skinning" of my Little-endian blog. If you've been here before you will notice that it's already changed. As it stands now, it's a good start, but still needs work. I will do my best to detail my experiences and the process during this (and others as I come up with them) revision.</P>
<P>In the meantime, be sure to visit the Microsoft Expression website and download the <A title="Microsoft Expression - Try It!" href="http://www.microsoft.com/expression/try-it/#PageTop" target=_blank mce_href="http://www.microsoft.com/expression/try-it/#PageTop">free 60 day trial</A> and give our latest and greatest version a try!</P>]]></content:encoded>
    </item>
    <item>
      <title>Picture Perfect Expression Media Image Gallery</title>
      <link>https://docs.microsoft.com/archive/blogs/gsmith/picture-perfect-expression-media-image-gallery</link>
      <pubDate>Fri, 03 Oct 2008 02:09:00 GMT</pubDate>
      <dc:creator><![CDATA[Gregory W. Smith]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/gsmith/2008/10/03/picture-perfect-expression-media-image-gallery/</guid>
      <description><![CDATA[I used Expression Design to layout and create the elements for my wedding homepage and then used...]]></description>
      <content:encoded><![CDATA[<P>I used Expression Design to layout and create the elements for my <A class="" title="Wedding Website" href="http://www.gwsii.com/wedding" target=_blank mce_href="http://www.gwsii.com/wedding">wedding homepage</A> and then used Expression Web to position them on the page. After that I used Expression Web to give the page image swapping behaviors when the user moved the mouse over the titles of the page. In this final blog I will describe how I modified an existing HTML gallery in Expression Media to make up the remaining pages of the website.</P>
<P>I mentioned the HTML gallery in one of my first blog posts; they’re really easy to produce and there are several built in templates you can use. Once Expression Media is installed, the HTML gallery can be accesses under the Make menu, HTML Gallery …&nbsp;When selected, Expression Media will display a dialog of options.</P>
<P><IMG title="HTML Gallery Options Dialog" style="WIDTH: 415px; HEIGHT: 580px" height=580 alt="HTML Gallery Options Dialog" src="http://www.gwsii.com/blog/wedding/ExpressionMediaHTMLOptions.jpg" width=415 mce_src="http://www.gwsii.com/blog/wedding/ExpressionMediaHTMLOptions.jpg"></P>
<P>And there are so many options! So many, in fact, that the good people at Expression Media added the ability to save a set of options to disk.</P>
<P><IMG title="Save options menu" style="WIDTH: 118px; HEIGHT: 82px" height=82 alt="Save options menu" src="http://www.gwsii.com/blog/wedding/ExpressionMediaOptionsSaveM.jpg" width=118 mce_src="http://www.gwsii.com/blog/wedding/ExpressionMediaOptionsSaveM.jpg"></P>
<P>However, if the existing templates and all of the options provided still do not exactly produce what is desired, one can create custom HTML gallery templates, and Expression Web is a great tool to use.</P>
<P>The standard templates are located in the Expression Media install directory under the “\en\Plug-ins\HTML Templates” directory. Each of these template directories corresponds to one of the selections in the theme dropdown list in the HTML Options dialog.</P>
<P>There are three files and one directory found in each template. The index.html file describes what the page that hosts the thumbnail images looks like, media.html defines the page used for the full sized images and the about.jpg image is used to give the user a basic impression of what the gallery will look like. The about.jpg image is displayed to the user in the HTML Options dialog when the associated template is selected. Finally, the assets directory contains all the images and additional files referenced in the other two .html pages.</P>
<P>I started the creation of my custom template by copying an existing template directory and renaming it to “Wedding.” The new template is immediately available as a new theme in the HTML Options dialog and you can create galleries with it to test your changes as you go.</P>
<P><IMG title="New gallery theme in the list" style="WIDTH: 267px; HEIGHT: 246px" height=246 alt="New gallery theme in the list" src="http://www.gwsii.com/blog/wedding/ExpressionMediaNewTheme.jpg" width=267 mce_src="http://www.gwsii.com/blog/wedding/ExpressionMediaNewTheme.jpg"></P>
<P>Using Expression Web to open the template directory as a website and examining the index.html page reveals the pattern Expression Media uses to insert data into the HTML pages, “(iView:*).” Whenever Expression Media encounters this pattern in the HTML pages in your template it will replace the pattern with the corresponding information about your gallery. For example, it will replace “(iView:Catalog)” with the Site Title in the HTML Options dialog and “(iView:Capation)” with the caption of the image in the media.html file.</P>
<P><IMG title="Editing the index.html page in Expression Web" style="WIDTH: 600px; HEIGHT: 149px" height=149 alt="Editing the index.html page in Expression Web" src="http://www.gwsii.com/blog/wedding/ExpressionWebThemeHead.jpg" width=600 mce_src="http://www.gwsii.com/blog/wedding/ExpressionWebThemeHead.jpg"></P>
<P>Defining the meanings of all of these “iView” values is beyond the scope of this article, but by examining the existing templates and the HTML that is generated from them, their meanings can be discovered.</P>
<P>The index.html and media.html pages may be modified in Expression Web and any resources those pages require (images or CSS files for example) can be saved to the assets directory and referenced with a relative URL. Once you are happy with the changes you have made, save the files from Expression Web, generate the HTML gallery and publish it. One nice finishing touch would be to create an image to represent the new gallery theme and save it as about.jpg with a resolution of 200 x 120 pixels.</P>
<P><IMG title="Wedding gallery theme image" style="WIDTH: 200px; HEIGHT: 120px" height=120 alt="Wedding gallery theme image" src="http://www.gwsii.com/blog/wedding/about.jpg" width=200 mce_src="http://www.gwsii.com/blog/wedding/about.jpg"></P>
<P>In the final version of my website, I actually created four different galleries, one for each category of images. I am still getting images from friends and family who were at the wedding and by creating these custom galleries I can add those new images very easily.</P>
<P>Lastly, I have made a more generic version of the wedding gallery available for <A class="" title="Wedding HTML gallery template" href="http://www.gwsii.com/blog/wedding/Wedding.zip" mce_href="http://www.gwsii.com/blog/wedding/Wedding.zip">download</A>, feel free to use it and modify it as you see fit.</P>]]></content:encoded>
    </item>
    <item>
      <title>Make Your Web Pages "Behave" by Swapping Images</title>
      <link>https://docs.microsoft.com/archive/blogs/gsmith/make-your-web-pages-behave-by-swapping-images</link>
      <pubDate>Tue, 23 Sep 2008 10:00:00 GMT</pubDate>
      <dc:creator><![CDATA[Gregory W. Smith]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/gsmith/2008/09/23/make-your-web-pages-behave-by-swapping-images/</guid>
      <description><![CDATA[I used Expression Design to layout and create the elements for my wedding homepage (see my blog...]]></description>
      <content:encoded><![CDATA[<P>I used Expression Design to layout and create the elements for my wedding homepage (see my blog <A class="" href="http://blogs.msdn.com/gsmith/archive/2008/09/03/designing-a-wedding-page-in-expression-design.aspx" mce_href="http://blogs.msdn.com/gsmith/archive/2008/09/03/designing-a-wedding-page-in-expression-design.aspx">Composing a Wedding Page in Expression Design</A>) and then used Expression Web to position them on the page. In this post I will describe how to use Expression Web to add image swapping behavior to the page.</P>
<P>Each of the image tags on the page is given appropriate alternate text and is also given meaningful IDs where I will give them behaviors. In order to make the page more interesting and more interactive I decided that the look of each link to a gallery and also the central image will change when the user moves their mouse over the link. I did this to give the use some feedback so that they would notice that the titles are, in fact, links to other content.</P>
<P><IMG title="Selected Image and its properties" style="WIDTH: 500px; HEIGHT: 188px" height=188 alt="Selected Image and its properties" src="http://www.gwsii.com/blog/wedding/WeddingImagesTagProps.jpg" width=500 mce_src="http://www.gwsii.com/blog/wedding/WeddingImagesTagProps.jpg"></P>
<P>Previously in Expression Design, I created the alternate title images that will replace the normal ones for the Image Swap behaviors. I also prepared four more cropped images from the wedding that will replace the black and white one used in the original composition. </P>
<P>&nbsp;<IMG title="Image without mouseover" style="WIDTH: 543px; HEIGHT: 323px" height=323 alt="Image without mouseover" src="http://www.gwsii.com/blog/wedding/WeddingPageMouseOut.jpg" width=543 mce_src="http://www.gwsii.com/blog/wedding/WeddingPageMouseOut.jpg"></P>
<P>Swapping those images out really makes the interaction with the page “pop” by injecting color on an otherwise monochrome image.</P>
<P><IMG title="Image with mouseover" style="WIDTH: 540px; HEIGHT: 322px" height=322 alt="Image with mouseover" src="http://www.gwsii.com/blog/wedding/WeddingPageMouseIn.jpg" width=540 mce_src="http://www.gwsii.com/blog/wedding/WeddingPageMouseIn.jpg"></P>
<P>Selecting one of the images from the page&nbsp; (like in the picture above) and opening the Behaviors task pane via the Task Panes menu allows you to define a number of different kinds of behaviors for that image or element. Press the “Insert” button and select “Swap Image” from the menu.</P>
<P><IMG title="Behaviors Taskpane" style="WIDTH: 251px; HEIGHT: 459px" height=459 alt="Behaviors Taskpane" src="http://www.gwsii.com/blog/wedding/ExpressionWebBehaviorSwap.jpg" width=251 mce_src="http://www.gwsii.com/blog/wedding/ExpressionWebBehaviorSwap.jpg"></P>
<P>You will then be presented with the Swap Image dialog box which you can use to change the images on a page when the use moves their mouse over the image you currently have selected. In the example below, the settings for this image will swap out the existing image (ID is “WeddingTitleImage”) with the “light” version of that image and also change the page’s main image (ID is “MainImage”) with the color version of that image. There are also two other options, Preload Images will download the images using JavaScript immediately when the page is initially loaded (for smooth animation) and Restore on mouseoutevent will automatically restore the image when the user moves their mouse out of the selected image.</P>
<P><IMG title="Swap Images Dialog" style="WIDTH: 531px; HEIGHT: 472px" height=472 alt="Swap Images Dialog" src="http://www.gwsii.com/blog/wedding/ExpressionWebSwapImagesDial.jpg" width=531 mce_src="http://www.gwsii.com/blog/wedding/ExpressionWebSwapImagesDial.jpg"></P>
<P>I found this to be a very easy way to get this functionality, since I have wasted lots of time writing and debugging my own JavaScript in the past. Once I have configured the Swap Image settings for the other three title image, the page’s functionality is complete. </P>
<P>I tested this page in Internet Explorer 6, 7 and 8 Beta, Firefox, Opera, Safari for Windows and the new Google Chrome Beta. The CSS layout and the JavaScript code to swap the images performed perfectly in every case.</P>
<P>I'm still working on it but you can view the work in progress here: <A class="" title="Wedding Website" href="http://www.gwsii.com/wedding/" mce_href="http://www.gwsii.com/wedding/">wedding website</A>. I'll keep blogging about my progress as I continue to use Expression Studio programs to add to the site more and more. Next I will explore using Expression Media to create the actual image galleries.</P>]]></content:encoded>
    </item>
    <item>
      <title>Using a Tracing Image in Expression Web to Guide Page Layout</title>
      <link>https://docs.microsoft.com/archive/blogs/gsmith/using-a-tracing-image-in-expression-web-to-guide-page-layout</link>
      <pubDate>Wed, 10 Sep 2008 02:05:00 GMT</pubDate>
      <dc:creator><![CDATA[Gregory W. Smith]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/gsmith/2008/09/10/using-a-tracing-image-in-expression-web-to-guide-page-layout/</guid>
      <description><![CDATA[I used Expression Design to layout and create the elements for my wedding homepage (see my blog...]]></description>
      <content:encoded><![CDATA[<P>I used Expression Design to layout and create the elements for my wedding homepage (see my blog <A title="Composing a Wedding Page in Expression Design" href="http://blogs.msdn.com/gsmith/archive/2008/09/03/designing-a-wedding-page-in-expression-design.aspx" mce_href="http://blogs.msdn.com/gsmith/archive/2008/09/03/designing-a-wedding-page-in-expression-design.aspx">Composing a Wedding Page in Expression Design</A>.) In this&nbsp;post I will describe how to use Expression Web to layout those elements on the page based on the composition image.</P>
<P>Using a Tracing Image is one way a web developer can be sure that the web page that they’re marking up will look like the page the designer intended. The tracing image is just an image you can make appear in the background of the Design view of Expression Web to guide you; the tracing image doesn’t appear in the web browser.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Use the Tracing Image, Configure … option under the View menu to set up a tracing image for the page.</P>
<P mce_keep="true"><IMG style="WIDTH: 303px; HEIGHT: 178px" title="Tracing Image menu in Expression Web" alt="Tracing Image menu in Expression Web" src="http://www.gwsii.com/Blog/Wedding/ExpressionWebTraceMenu.jpg" width=303 height=178 mce_src="http://www.gwsii.com/Blog/Wedding/ExpressionWebTraceMenu.jpg"></P>
<P>Use the Browse … button to pick an image file from your hard disk, then you can change the offset from the upper left corner of the page, with an X and Y offset, or you can base the offset on the position of the currently selected element in the design surface. Additionally, you can control the transparency of the tracing image by using the Opacity slider near the bottom of the dialog. Here are the settings I used for my tracing image.</P>
<P><IMG style="WIDTH: 451px; HEIGHT: 286px" title="Tracing Image configuration dialog in Expression Web" alt="Tracing Image configuration dialog in Expression Web" src="http://www.gwsii.com/Blog/Wedding/ExpressionWebTraceDialog.jpg" width=451 height=286 mce_src="http://www.gwsii.com/Blog/Wedding/ExpressionWebTraceDialog.jpg"></P>
<P>Expression Web adds a “magic comment” to your HTML document that instructs Expression Web to display your composition image; web browsers will ignore this comment and the tracing image. Notice how the body of the page is empty, but you can see the Tracing Image on the design surface. Once this image is in place, you can start to position your DIV elements and images. For the DIVs that comprise the matting around the page, I was able to use the margins and border attributes.</P>
<P mce_keep="true"><IMG style="WIDTH: 500px; HEIGHT: 304px" title="The Tracing Image comment and example." alt="The Tracing Image comment and example." src="http://www.gwsii.com/Blog/Wedding/ExpressionWebTraceTag.jpg" width=500 height=304 mce_src="http://www.gwsii.com/Blog/Wedding/ExpressionWebTraceTag.jpg"></P>
<P>Making the outermost DIV relatively positioned and then all of the elements contained by that DIV absolutely positioned, you can precisely control the positioning of the elements on the page and make them overlay the tracing image perfectly. </P>
<P mce_keep="true"><IMG style="WIDTH: 500px; HEIGHT: 416px" title="Positioning an image over a trace in Expression Web" alt="Positioning an image over a trace in Expression Web" src="http://www.gwsii.com/Blog/Wedding/ExpressionWebImagePos.jpg" width=500 height=416 mce_src="http://www.gwsii.com/Blog/Wedding/ExpressionWebImagePos.jpg"></P>
<P>While using the tracing image in Expression Web, I found it easier to remove any background styled of DIV elements that would otherwise cover over the background of the page. Once you are done placing elements in their proper locations, you can then give the DIV elements the appropriate background styles. Here is what the design view of the page looks like with all of the images placed in it located correctly over the Trace Image.</P>
<P mce_keep="true"><IMG style="WIDTH: 500px; HEIGHT: 316px" title="All images positioned over trace for final layout." alt="All images positioned over trace for final layout." src="http://www.gwsii.com/Blog/Wedding/ExpressionWebImageSelect.jpg" width=500 height=316 mce_src="http://www.gwsii.com/Blog/Wedding/ExpressionWebImageSelect.jpg"></P>
<P>Using styles like this is really great because you can layout all the elements of the page where ever you want them without having to use HTML tables or other awkward and confusing mechanisms. Additionally, the “meaning” of the HTML can be inferred because it remains relatively simple. The four images for the gallery pages are contained in an unordered list and wrapped in hyperlink tags. So from a semantic standpoint, the page can be seen for what it basically is: a list of four links to other image galleries. There are no other structural tags, such as a tables or cells, used only for layout to confuse the meaning of the content.</SPAN></P>
<P>I'm still working on it but you can view the work in progress here: <A title="Wedding Website" target=_blank href="http://www.gwsii.com/wedding/" mce_href="http://www.gwsii.com/wedding/">wedding website</A>. I'll keep blogging about my progress as I continue to use Expression Studio programs to add to the site more and more. Next I will explore using Expression Web to add image swapping behaviors.</P>]]></content:encoded>
    </item>
    <item>
      <title>Composing a Wedding Page in Expression Design</title>
      <link>https://docs.microsoft.com/archive/blogs/gsmith/composing-a-wedding-page-in-expression-design</link>
      <pubDate>Wed, 03 Sep 2008 12:55:00 GMT</pubDate>
      <dc:creator><![CDATA[Gregory W. Smith]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/gsmith/2008/09/03/composing-a-wedding-page-in-expression-design/</guid>
      <description><![CDATA[In August of&nbsp;2008 I was lucky enough to marry the woman of my dreams&nbsp;with a small wedding...]]></description>
      <content:encoded><![CDATA[<P mce_keep="true">In August of&nbsp;2008 I was lucky enough to marry the woman of my dreams&nbsp;with a small wedding ceremony in Las Vegas. I really enjoy web design and while I am not a professional web designer, I get to play one at my new job as a software tester on the Expression Web team at Microsoft in Redmond. Because I wanted to learn more about the products in Expression Studio I chose to use them to build a website to commemorate our wedding and to share this event with the world.</P>
<P><IMG title="Wedding homepage" style="WIDTH: 500px; HEIGHT: 313px" height=313 alt="Wedding homepage" src="http://www.gwsii.com/blog/wedding/WeddingPageSnapshot.jpg" width=500 align=middle mce_src="http://www.gwsii.com/blog/wedding/WeddingPageSnapshot.jpg"></P>
<P>The first step was to compose a homepage. Expression Design turned out to be the perfect tool for this because of its ability to create beautiful scalable vector art and how very easy it is to export web-ready bitmaps from it.</P>
<P>I began by designing a logo for the site. My wife, Paula, loves lilies and made them a big part of the wedding and so I decided to use a pair of these flowers to represent our union. The color for our wedding was black and white so that drove the decision to use those colors for the art. She's also a pretty cool chick so she really likes the tribal border that creates a heart shape around the lilies. The tribal border is a preset brush labeled “Tattoo” that you can “paint” with in Expression Design. </P>
<P><IMG title="Heart with lilies in Expression Design" style="WIDTH: 371px; HEIGHT: 467px" height=467 alt="Heart with lilies in Expression Design" src="http://www.gwsii.com/blog/wedding/WeddingPageLiliesHeart.jpg" width=371 align=middle mce_src="http://www.gwsii.com/blog/wedding/WeddingPageLiliesHeart.jpg"></P>
<P>Once I saved the individual logo, I created a new Expression Design file that would be the overall composition image for the page. I made the file 955 x 600 pixels because I am targeting a monitor with resolution 1024 x 768, and the page size option in the status bar of Expression Web recommends that size:</P>
<P><IMG title="Expression Web page size context menu." style="WIDTH: 270px; HEIGHT: 212px" height=212 alt="Expression Web page size context menu." src="http://www.gwsii.com/blog/wedding/WeddingPageSizeMenu.jpg" width=270 align=middle mce_src="http://www.gwsii.com/blog/wedding/WeddingPageSizeMenu.jpg"></P>
<P>&nbsp;...so that's the size I based the Design file on. I copied the logo into the composition and created the other page elements quickly with Design. Looking at the layout I decided that I would take each element on the page and use CSS to lay them out on the web page.</P>
<P><IMG title="Homepage Composition in Expression Design" style="WIDTH: 511px; HEIGHT: 408px" height=408 alt="Homepage Composition in Expression Design" src="http://www.gwsii.com/blog/wedding/ExpressionDesignComp.jpg" width=511 align=middle mce_src="http://www.gwsii.com/blog/wedding/ExpressionDesignComp.jpg"></P>
<P>Next, I copied the individual elements that made up the composition into another part of the document, modified the titles to give them a different look when users mouse over them. <INS cite=mailto:Anna%20Ullrich dateTime=2008-09-03T14:19></INS></P>
<P><INS cite=mailto:Anna%20Ullrich dateTime=2008-09-03T14:19><IMG title="Titles for mouseover in Expression Design" alt="Titles for mouseover in Expression Design" src="http://www.gwsii.com/blog/wedding/WeddingTitlesModified.jpg" align=middle mce_src="http://www.gwsii.com/blog/wedding/WeddingTitlesModified.jpg"></INS></P>
<P>Once I had all of the individual parts in place, I was able to use the "slice" functionality of Design to create the bitmaps which will be used in the final page and give them each a name which will control the filename for the bitmap when they are exported.<INS cite=mailto:Anna%20Ullrich dateTime=2008-09-03T14:20></INS></P>
<P><INS cite=mailto:Anna%20Ullrich dateTime=2008-09-03T14:20><IMG title="Homepage elements with layers displayed." style="WIDTH: 500px; HEIGHT: 391px" height=391 alt="Homepage elements with layers displayed." src="http://www.gwsii.com/blog/wedding/WeddingTitleElementsWithLay.jpg" width=500 align=middle mce_src="http://www.gwsii.com/blog/wedding/WeddingTitleElementsWithLay.jpg"></INS></P>
<P>One note about the titles: by using the layers on top of the titles first and then copying the titles along with the slices, it was very easy to simply change the text color and border values to produce the mouse-over effect images.</P>
<P><IMG title="Title images copied in Expression Design" style="WIDTH: 500px; HEIGHT: 312px" height=312 alt="Title images copied in Expression Design" src="http://www.gwsii.com/blog/wedding/WeddingTitleLayersCopied.jpg" width=500 align=middle mce_src="http://www.gwsii.com/blog/wedding/WeddingTitleLayersCopied.jpg"></P>
<P>The exporting functionality really came in handy when I remembered that IE6 did not handle transparency in PNG files&nbsp;correctly. I was easily able to change the file type of the layers to&nbsp;GIF images and then re-export them in seconds.</P>
<P><IMG title="Exporting slices from Expression Design" style="WIDTH: 500px; HEIGHT: 425px" height=425 alt="Exporting slices from Expression Design" src="http://www.gwsii.com/blog/wedding/ExpressionDesignExportSlice.jpg" width=500 align=middle mce_src="http://www.gwsii.com/blog/wedding/ExpressionDesignExportSlice.jpg"></P>
<P>I'm still working on it but you can view the work in progress here: <A title="Greg and Paula's Wedding Site" href="http://www.gwsii.com/wedding/default.html" target=_blank mce_href="http://www.gwsii.com/wedding/default.html">wedding website</A> . I'll keep blogging about my progress as I continue to use Expression Studio programs to add to&nbsp;the site more and more.&nbsp;Next I will explore using Expression Web for behaviors and layout of the homepage.</P>]]></content:encoded>
    </item>
  </channel>
</rss>