<?xml version="1.0" encoding="utf-8"?><rss version="2.0">
<channel>
<title><![CDATA[Steve Hawley]]></title>
<link><![CDATA[http://www.atalasoft.com/blogs/blogsrss.aspx?rss=stevehawley]]></link>
<description><![CDATA[Steve Hawley Atalasoft RSS]]></description>
<language><![CDATA[en-US]]></language>

<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/january-2012/please-don’t-mind-the-dust]]></guid>
     <title><![CDATA[Please Don’t Mind the Dust]]></title>
     <description><![CDATA[<p>
	Atalasoft is moving the blogs to new hosting software.&nbsp; In the meantime, here are a few favorites of mine from the past:</p>
<p>
	&nbsp;</p>
<ul>
	<li>
		<a href="http://atalasoft.com/cs/blogs/stevehawley/archive/2009/03/25/14-things-every-software-engineer-should-know.aspx">14 Things Every Software Engineer Should Know</a></li>
	<li>
		<a href="http://atalasoft.com/cs/blogs/stevehawley/archive/2010/08/03/protect-yourself.aspx">Protect Yourself</a></li>
	<li>
		<a href="http://atalasoft.com/cs/blogs/stevehawley/archive/2010/07/08/why-software-has-bugs.aspx">Why Software Has Bugs</a></li>
	<li>
		<a href="http://atalasoft.com/cs/blogs/stevehawley/archive/2006/03/03/9632.aspx">Robotron and OOP</a></li>
</ul>
]]></description>
     <pubDate>Thu, 19 Jan 2012 10:52:58 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/january-2012/please-don’t-mind-the-dust]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/making-your-own-shapes]]></guid>
     <title><![CDATA[DotPdf: Making Your Own Shapes]]></title>
     <description><![CDATA[<p>
	One of the main ways of creating page content in <a href="http://atalasoft.com/products/dotpdf">DotPdf</a> is to use shapes.&nbsp; We give you a number of &ldquo;canned&rdquo; shapes that are very easy to work with (circle, rectangle, path, text, etc.), but you will probably need to make your own shapes at some point.&nbsp; This article is going to show you one way to do that that is very easy.</p>
<p>
	&nbsp;</p>
<p>
	Let&rsquo;s say that you need to create a letterhead that needs to have a donut in the logo.&nbsp; You could just draw the donut directly, but let&rsquo;s say that you&rsquo;re trying to create a whole corporate presence around donuts and you need to draw a lot of donuts in a lot of places.&nbsp; The way to do that is to make a shape.</p>
<p>
	What is a donut?&nbsp; It&rsquo;s two circles of different radii drawn at the same center with a fill color and an outline color.&nbsp; Great &ndash; these feel like things to pass to the constructor and for some properties.&nbsp; We&rsquo;ll start by making a Donut class that is a subclass of PdfBaseShape:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> System;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> System.Drawing;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> Atalasoft.PdfDoc.Generating.Shapes;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> Atalasoft.PdfDoc.Generating;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> Atalasoft.PdfDoc.Geometry;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">namespace</span> DonutShape
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    [Serializable]
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Donut : PdfBaseShape
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> Donut(PdfPoint center, <span style="color: #0000ff">double</span> innerRadius, <span style="color: #0000ff">double</span> outerRadius, IPdfColor outlineColor, <span style="color: #0000ff">double</span> linewidth, IPdfColor fillColor)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            : <span style="color: #0000ff">base</span>(outlineColor, linewidth, fillColor)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            Center = center;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            OuterRadius = outerRadius;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            InnerRadius = innerRadius;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> Donut(PdfPoint center, <span style="color: #0000ff">double</span> innerRadius, <span style="color: #0000ff">double</span> outerRadius)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            : <span style="color: #0000ff">this</span>(center, innerRadius, outerRadius, PdfColorFactory.FromColor(Color.Black), 1.0, PdfColorFactory.FromColor(Color.Brown))
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> PdfBaseShape CloneInstance()
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> Donut(Center, InnerRadius, OuterRadius); <span style="color: #008000">// colors will get set by the base class</span>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> DrawShape(Atalasoft.PdfDoc.Generating.Rendering.PdfPageRenderer r)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> NotImplementedException();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> PdfPoint Center { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> OuterRadius { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> InnerRadius { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	In this case, I made two constructors, one that takes the line color, line thickness and fill color and one that creates a default.&nbsp; Since colors and line styles are handled by the base class, we can just pass those on and forget about them for now.&nbsp; There are really only two pieces of work: be able to clone the shape and be able to draw the shape.&nbsp; Cloning is easy &ndash; just call a constructor with the center and radii.&nbsp; Drawing is also easy, but let&rsquo;s concentrate on that code on its own:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> DrawShape(Atalasoft.PdfDoc.Generating.Rendering.PdfPageRenderer r)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    PdfCircle outer = <span style="color: #0000ff">new</span> PdfCircle(Center, OuterRadius, OutlineColor, Style.Width, FillColor);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    PdfCircle inner = <span style="color: #0000ff">new</span> PdfCircle(Center, InnerRadius, OutlineColor, Style.Width, PdfColorFactory.FromColor(Color.White));
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    outer.Render(r);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    inner.Render(r);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	In this routine, I create two circles, one for the outer circle and one for the inner.&nbsp; The outer I create with the Donut&rsquo;s line and fill properties.&nbsp; The inner I do the same except that the fill I set to white.&nbsp; I can try it out with the following test code:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
PdfGeneratedDocument doc = <span style="color: #0000ff">new</span> PdfGeneratedDocument();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
PdfGeneratedPage page = PdfDefaultPages.Letter;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
doc.Pages.Add(page);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
Donut donut = <span style="color: #0000ff">new</span> Donut(<span style="color: #0000ff">new</span> PdfPoint(288, 400), 18, 100);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
page.DrawingList.Add(donut);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
doc.Save(&quot;<span style="color: #8b0000">donut.pdf</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	When I run the app, I get a page that looks like this:</p>
<p>
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=24fdc5b9-87f6-4747-8b90-4cb8af027087"><img alt="image" border="0" height="307" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=213516a8-c90b-4c75-998d-f7cadd130888" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" width="240" /></a></p>
<p>
	Hooray &ndash; that&rsquo;s just what I expected!&nbsp; There&rsquo;s a problem, though.&nbsp; If we draw the donut over the top of something else it will cover it up entirely, which is not what we expected:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
PdfGeneratedDocument doc = <span style="color: #0000ff">new</span> PdfGeneratedDocument();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
PdfGeneratedPage page = PdfDefaultPages.Letter;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
doc.Pages.Add(page);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #008000">// Add a red line from the center out</span>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
PdfPath path = <span style="color: #0000ff">new</span> PdfPath(PdfColorFactory.FromColor(Color.Red), 8);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
path.MoveTo(288, 400);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
path.LineTo(500, 500);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
page.DrawingList.Add(path);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
Donut donut = <span style="color: #0000ff">new</span> Donut(<span style="color: #0000ff">new</span> PdfPoint(288, 400), 18, 100);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
page.DrawingList.Add(donut);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
doc.Save(&quot;<span style="color: #8b0000">donut.pdf</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=a9930844-bd77-468e-9657-2702c44928df"><img alt="image" border="0" height="309" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=f8afdbe9-ca3b-4e08-86ff-487eda610711" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" width="238" /></a></p>
<p>
	The problem is clear &ndash; the inner circle is being painted white.&nbsp; This will cover up anything under it.&nbsp; In fact, we depend on that to cover up the brown donut.&nbsp; The solution is to change our approach.&nbsp; Instead of using two PdfCircle shapes, we&rsquo;re going to use one PdfPath shape to represent both circles.&nbsp; A path is a collection of operations that include move, draw line, draw Bezier curve, close the path.&nbsp; The really cool thing is that a path can contain any number of possibly disjoint subpaths, so two circles are easy.&nbsp; To start off with, we need a routine that give a PdfPath shape will add in a circle composed of Bezier curves.&nbsp; To do this, I&rsquo;ll break this out into a new method.&nbsp; The code presented here is based on <a href="http://www.tinaja.com/glib/ellipse4.pdf">an article</a> by Don Lancaster.&nbsp; If you want to learn a great deal about the math behind Bezier curves, <a href="http://www.tinaja.com/cubic01.asp">this is a great place to start</a>.</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> DrawShape(Atalasoft.PdfDoc.Generating.Rendering.PdfPageRenderer r)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    PdfPath path = <span style="color: #0000ff">new</span> PdfPath(OutlineColor, Style.Width, FillColor);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    MakeCircle(path, OuterRadius, Center);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    MakeCircle(path, InnerRadius, Center);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    path.Render(r);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> PdfPath MakeCircle(PdfPath path, <span style="color: #0000ff">double</span> radius, PdfPoint center)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">double</span> magic = 0.551784 * radius;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    path.MoveTo(<span style="color: #0000ff">new</span> PdfPoint(-radius, 0) + center);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    path.CurveTo(<span style="color: #0000ff">new</span> PdfPoint(-radius, magic) + center, <span style="color: #0000ff">new</span> PdfPoint(-magic, radius) + center, <span style="color: #0000ff">new</span> PdfPoint(0, radius) + center);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    path.CurveTo(<span style="color: #0000ff">new</span> PdfPoint(magic, radius) + center, <span style="color: #0000ff">new</span> PdfPoint(radius, magic) + center, <span style="color: #0000ff">new</span> PdfPoint(radius, 0) + center);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    path.CurveTo(<span style="color: #0000ff">new</span> PdfPoint(radius, -magic) + center, <span style="color: #0000ff">new</span> PdfPoint(magic, -radius) + center, <span style="color: #0000ff">new</span> PdfPoint(0, -radius) + center);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    path.CurveTo(<span style="color: #0000ff">new</span> PdfPoint(-magic, -radius) + center, <span style="color: #0000ff">new</span> PdfPoint(-radius, -magic) + center, <span style="color: #0000ff">new</span> PdfPoint(-radius, 0) + center);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">return</span> path;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=baeda093-fda3-4fe9-aa34-04760bf3887a"><img alt="image" border="0" height="306" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=aac847c0-7513-46f6-bb17-5e84a89a8080" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" width="237" /></a></p>
<p>
	&nbsp;</p>
<p>
	And, tada, here is our shape.&nbsp; The question is, why isn&rsquo;t the donut hole filled?&nbsp; The answer is that PDF has two different ways to fill paths.&nbsp; The first is called the Even-Odd Rule.&nbsp; The PDF renderer figures out how many lines have been crossed as it goes left to right.&nbsp; If the number is odd, it fills.&nbsp; If the number is even it doesn&rsquo;t.&nbsp; This is the default method for filling.&nbsp; The other method is called the Non-Zero Winding Rule.&nbsp; It is more complicate and has to do with the direction that lines are drawn as they cross the scanline being filled.&nbsp; Lines that cross bottom to top add 1 to the winding number.&nbsp; Lines that cross top to bottom take one away.&nbsp; If the winding number is non-zero, the scanline gets filled.&nbsp; If this circle had been filled with NZW, the center would be brown and cover up the red line.</p>
<p>
	As a final best practice rule for making reusable shapes: make shapes as generic as possible and put them into their own assembly away from the rest of your application.&nbsp; This will make it easier to reuse the shape in other projects and will make it more easier to reload the PDF in DotPdf for further editing.</p>
]]></description>
     <pubDate>Mon, 23 Jan 2012 12:20:33 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/making-your-own-shapes]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/february-2012/working-with-dotpdf-shapes-or-shape-generators]]></guid>
     <title><![CDATA[Working with DotPdf - Shapes or Shape Generators?]]></title>
     <description><![CDATA[<p>
	<a href="http://atalasoft.com/products/dotpdf">DotPdf</a> comes with a number of built-in shapes and as I mentioned in a previous blog, it&rsquo;s easy to define new shapes.&nbsp; It&rsquo;s very easy to make shapes, but sometimes we can get carried away and lose sense of what should be a shape and what should not be a shape.&nbsp; This blog is going to be about guidelines for categorizing your page elements and infrastructure for making large-scale document production easier.</p>
<p>
	First, let&rsquo;s talk about what makes a shape.&nbsp; A shape should be:</p>
<ul>
	<li>
		Simple to represent in data (ie, you should be able to attach the [Serializable] attribute and not worry about what happens with default behaviors)</li>
	<li>
		It should be blissfully unaware of the page on which it sits (or more precisely the drawing list in which it resides)</li>
	<li>
		It should have absolutely no business logic</li>
</ul>
<p>
	Now, let&rsquo;s talk about what makes a shape generator.&nbsp; A shape generator can/should be:</p>
<ul>
	<li>
		Simple or complex in data representation (it may pull its data from elsewhere)</li>
	<li>
		Aware (or unaware) of page layout</li>
	<li>
		Nearly all logic (business or layout)</li>
</ul>
<p>
	Let&rsquo;s take an example &ndash; suppose you want to make a system to generate ebooks on the fly and you want to have page automatic page numbering.&nbsp; You could do that with a page number shape.&nbsp; It fits the categories above &ndash; for representation, you need the page number, the location on the page (but you don&rsquo;t really care where).&nbsp; It&rsquo;s pretty simple.&nbsp; At least it seems pretty simple, until you start considering how page numbers are laid out in reality.&nbsp; First, page numbers can be at the top or the bottom of the page.&nbsp; Second, the page numbers can be on verso (left) or recto (right)&nbsp; or center or alternating recto/verso.&nbsp; Finally page numbers can be in either Roman (upper or lower) or Arabic numerals.&nbsp; Phew.</p>
<p>
	This to me says that the actual page number itself is a shape, but everything around it is a generator that should be encapsulated.&nbsp; So let&rsquo;s make that generator.&nbsp; First we&rsquo;ll start with a few enumerations:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> <span style="color: #0000ff">enum</span> VerticalPositionStyle
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    TopRelative,
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    BottomRelative
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> <span style="color: #0000ff">enum</span> HorizontalPositionStyle
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    Center,
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    Left,
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    Right,
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    Alternating
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}</pre>
<p>
	These enums will let us decide how to position the shape on the page.&nbsp; Now let&rsquo;s think about the data that we need to represent a page number generator.&nbsp; We&rsquo;ll need the page number, the name of the font resource, the font size, the offset from either the top or bottom of the page, the left and right margins and whether or not we are working in Roman numerals.&nbsp; So for this: let&rsquo;s lay out some properties:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FontResourceName { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> FontSize { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> Current { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> VerticalOffset { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> LeftMargin { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> RightMargin { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> IsRomanNumerals { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> VerticalPositionStyle VerticalPositionStyle { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> HorizontalPositionStyle HorizontalPositionStyle { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	These are all straightforward &ndash; if these were my own code for release, I would null check FontResourceName and range check FontSize at the very least, but this is sample code, so better to be brief.</p>
<p>
	Given these, we can set up a constructor:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> PageNumberGenerator(<span style="color: #0000ff">string</span> fontResourceName, <span style="color: #0000ff">double</span> fontSize)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">if</span> (fontResourceName == <span style="color: #0000ff">null</span>) <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentNullException(&quot;<span style="color: #8b0000">fontResourceName</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">if</span> (fontSize &lt;= 0) <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentOutOfRangeException(&quot;<span style="color: #8b0000">fontSize</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    VerticalPositionStyle = VerticalPositionStyle.BottomRelative;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    HorizontalPositionStyle = HorizontalPositionStyle.Alternating;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    FontResourceName = fontResourceName;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    FontSize = fontSize;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    VerticalOffset = 72 * .75;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    LeftMargin = 72.0;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    RightMargin = 72.0;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    IsRomanNumerals = <span style="color: #0000ff">false</span>;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    Current = 1;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	Again, no surprises.&nbsp; So how do we generate the content?&nbsp; For this, I broke it out very procedurally:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> <span style="color: #0000ff">virtual</span> IPdfRenderable NextPageNumber(PdfGeneratedPage page)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">double</span> y = GetYPosition(page);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">double</span>[] xs = GetXStartAndEnd(page);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    PdfTextBox textBox = <span style="color: #0000ff">new</span> PdfTextBox(<span style="color: #0000ff">new</span> PdfBounds(xs[0], y, Math.Abs(xs[1] - xs[0]), FontSize + 2), FontResourceName, FontSize);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    textBox.Alignment = GetAlignment();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    textBox.Text = GetNumberText();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    AdvanceCurrent();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">return</span> textBox;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	In this code, I get the y position of the text and the start and end x coordinates.&nbsp; I make a PdfTextBox with bounds set so that the box covers the entire distance from left margin to right margin at the given y coordinate.&nbsp; This isn&rsquo;t strictly necessary &ndash; we could just figure out where to put the text and use a PdfTextLine, but PdfTextBox will do all the alignment for us, so why sweat it?&nbsp; Finally, we set the text of the box, advance the page number and move on.</p>
<p>
	With the process written, we can worry about filling in the sub tasks.&nbsp; First &ndash; getting the y position:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">double</span> GetYPosition(PdfGeneratedPage page)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">switch</span> (VerticalPositionStyle)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">case</span> VerticalPositionStyle.BottomRelative:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">return</span> VerticalOffset;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">case</span> VerticalPositionStyle.TopRelative:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">return</span> page.MediaBox.Top - VerticalOffset;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">default</span>:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentException(&quot;<span style="color: #8b0000">VerticalPositionStyle</span>&quot;, &quot;<span style="color: #8b0000">VerticalPositionStyle is out of range</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	For this, we calculate Y based on whether it needs to be relative to the bottom or the top.&nbsp; Now &ndash; getting the x positions:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">double</span>[] GetXStartAndEnd(PdfGeneratedPage page)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">double</span>[] xs = <span style="color: #0000ff">new</span> <span style="color: #0000ff">double</span>[2];
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    xs[0] = LeftMargin;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    xs[1] = page.MediaBox.Right - RightMargin;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">return</span> xs;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	Again, straight forward.&nbsp; I don&rsquo;t like making the array, but I like it more than using out parameters.&nbsp; It&rsquo;d be nice to have tuples.&nbsp; Now getting the alignment:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> PdfTextAlignment GetAlignment()
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">switch</span> (HorizontalPositionStyle)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">case</span> HorizontalPositionStyle.Center:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">return</span> PdfTextAlignment.Center;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">case</span> HorizontalPositionStyle.Left:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">return</span> PdfTextAlignment.Left;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">case</span> HorizontalPositionStyle.Right:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">return</span> PdfTextAlignment.Right;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">case</span> HorizontalPositionStyle.Alternating:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">return</span> (Current &amp; 1) == 0 ? PdfTextAlignment.Left : PdfTextAlignment.Right;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">default</span>:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentException(&quot;<span style="color: #8b0000">HorizontalPositionStyle</span>&quot;, &quot;<span style="color: #8b0000">HorizontalPositionStyle is out of range</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	How easy!&nbsp; The only trick is for alternating &ndash; I use the 0 bit of the page number to determine odd/even and switch between left and right based on that.&nbsp; Now getting the number text and advancing the number:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">string</span> GetNumberText()
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">return</span> IsRomanNumerals ? Current.ToRoman(<span style="color: #0000ff">false</span>) : Current.ToString();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> AdvanceCurrent()
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    Current += 1;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	For Roman numerals, I made an extension method on int that creates a string in Roman numerals from the int in either upper or lower case.&nbsp; I found <a href="http://www.blackwasp.co.uk/NumberToRoman.aspx">a very nice implementation here</a> and I wrapped it up in an extension method.&nbsp; I&rsquo;ll post the whole thing at the end.&nbsp; So how does this feel when it&rsquo;s put into usage?&nbsp; Not bad at all:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
PdfGeneratedDocument doc = <span style="color: #0000ff">new</span> PdfGeneratedDocument();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">string</span> tnr = doc.Resources.Fonts.AddFromFontName(&quot;<span style="color: #8b0000">Times New Roman</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
PageNumberGenerator gen = <span style="color: #0000ff">new</span> PageNumberGenerator(tnr, 10);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
gen.IsRomanNumerals = <span style="color: #0000ff">true</span>;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
gen.HorizontalPositionStyle = HorizontalPositionStyle.Center;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; 10; i++)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    PdfGeneratedPage page = PdfDefaultPages.Letter;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    page.DrawingList.Add(gen.NextPageNumber(page));
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    doc.Pages.Add(page);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
gen.IsRomanNumerals = <span style="color: #0000ff">false</span>;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
gen.HorizontalPositionStyle = HorizontalPositionStyle.Alternating;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
gen.Current = 1;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; 5; i++)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    PdfGeneratedPage page = PdfDefaultPages.Letter;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    page.DrawingList.Add(gen.NextPageNumber(page));
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    doc.Pages.Add(page);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
doc.Save(&quot;<span style="color: #8b0000">numberedpages.pdf</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	In this code I&rsquo;m making 15 pages, the first 5 are in Roman numerals, the rest in Arabic.&nbsp; Now as you&rsquo;re reading through this code you&rsquo;ll notice that all the procedural steps are protected virtual methods.&nbsp; Why?&nbsp; The answer is that by sublcassing the PageNumberGenerator you could make a number of changes that are tuned to your needs.&nbsp; For example, you could override the GetNumberText() method and make it look like this:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">string</span> GetNumberTest()
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">string</span> num = super.GetNumerText();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">return</span> &quot;<span style="color: #8b0000">[</span>&quot; + &quot;<span style="color: #8b0000">]</span>&quot;;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}</pre>
<p>
	and put each page number in a box.&nbsp; You could also do something much more flexible like this:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FormatString { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">string</span> GetNumberText()
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">string</span> text = super.GetNumberText();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">return</span> String.Format(FomatString ?? text, text);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}</pre>
<p>
	which would let you use any formatting text.&nbsp; You could set it to &ldquo;Page {0} of 100&rdquo;.</p>
<p>
	You could also override the NextPageNumber method and call the main code but add adornments like lines around the text or embed the page number in a colored circle.</p>
<p>
	You can see that by making careful decisions about whether a page object is a shape or comes from a shape generator, it&rsquo;s easy to make very flexible code.&nbsp; Next time, I&rsquo;ll talk about how you can generalize the shape generator concept and treat PDF generation as a process of corralling sets of page generators.</p>
<p>
	Here are the classes used in their entirety.</p>
<p>
	First PageNumberGenerator:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> System;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> System.Collections.Generic;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> System.Linq;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> System.Text;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> Atalasoft.PdfDoc.Generating.Rendering;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> Atalasoft.PdfDoc.Generating;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> Atalasoft.PdfDoc.Generating.Shapes;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> Atalasoft.PdfDoc.Geometry;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">namespace</span> PageNumberer
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">enum</span> VerticalPositionStyle
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        TopRelative,
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        BottomRelative
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">enum</span> HorizontalPositionStyle
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        Center,
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        Left,
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        Right,
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        Alternating
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> PageNumberGenerator
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> PageNumberGenerator(<span style="color: #0000ff">string</span> fontResourceName, <span style="color: #0000ff">double</span> fontSize)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">if</span> (fontResourceName == <span style="color: #0000ff">null</span>) <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentNullException(&quot;<span style="color: #8b0000">fontResourceName</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">if</span> (fontSize &lt;= 0) <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentOutOfRangeException(&quot;<span style="color: #8b0000">fontSize</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            VerticalPositionStyle = VerticalPositionStyle.BottomRelative;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            HorizontalPositionStyle = HorizontalPositionStyle.Alternating;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            FontResourceName = fontResourceName;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            FontSize = fontSize;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            VerticalOffset = 72 * .75;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            LeftMargin = 72.0;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            RightMargin = 72.0;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            IsRomanNumerals = <span style="color: #0000ff">false</span>;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            Current = 1;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">virtual</span> IPdfRenderable NextPageNumber(PdfGeneratedPage page)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">double</span> y = GetYPosition(page);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">double</span>[] xs = GetXStartAndEnd(page);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            PdfTextBox textPath = <span style="color: #0000ff">new</span> PdfTextBox(<span style="color: #0000ff">new</span> PdfBounds(xs[0], y, Math.Abs(xs[1] - xs[0]), FontSize + 2), FontResourceName, FontSize);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            textPath.Alignment = GetAlignment();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            textPath.Text = GetNumberText();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            AdvanceCurrent();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">return</span> textPath;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">double</span> GetYPosition(PdfGeneratedPage page)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">switch</span> (VerticalPositionStyle)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                <span style="color: #0000ff">case</span> VerticalPositionStyle.BottomRelative:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                    <span style="color: #0000ff">return</span> VerticalOffset;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                <span style="color: #0000ff">case</span> VerticalPositionStyle.TopRelative:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                    <span style="color: #0000ff">return</span> page.MediaBox.Top - VerticalOffset;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                <span style="color: #0000ff">default</span>:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                    <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentException(&quot;<span style="color: #8b0000">VerticalPositionStyle</span>&quot;, &quot;<span style="color: #8b0000">VerticalPositionStyle is out of range</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">double</span>[] GetXStartAndEnd(PdfGeneratedPage page)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">double</span>[] xs = <span style="color: #0000ff">new</span> <span style="color: #0000ff">double</span>[2];
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            xs[0] = LeftMargin;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            xs[1] = page.MediaBox.Right - RightMargin;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">return</span> xs;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> PdfTextAlignment GetAlignment()
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">switch</span> (HorizontalPositionStyle)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                <span style="color: #0000ff">case</span> HorizontalPositionStyle.Center:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                    <span style="color: #0000ff">return</span> PdfTextAlignment.Center;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                <span style="color: #0000ff">case</span> HorizontalPositionStyle.Left:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                    <span style="color: #0000ff">return</span> PdfTextAlignment.Left;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                <span style="color: #0000ff">case</span> HorizontalPositionStyle.Right:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                    <span style="color: #0000ff">return</span> PdfTextAlignment.Right;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                <span style="color: #0000ff">case</span> HorizontalPositionStyle.Alternating:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                    <span style="color: #0000ff">return</span> (Current &amp; 1) == 0 ? PdfTextAlignment.Left : PdfTextAlignment.Right;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                <span style="color: #0000ff">default</span>:
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                    <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentException(&quot;<span style="color: #8b0000">HorizontalPositionStyle</span>&quot;, &quot;<span style="color: #8b0000">HorizontalPositionStyle is out of range</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">string</span> GetNumberText()
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">return</span> IsRomanNumerals ? Current.ToRoman(<span style="color: #0000ff">false</span>) : Current.ToString();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> AdvanceCurrent()
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            Current += 1;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FontResourceName { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> FontSize { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> Current { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> VerticalOffset { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> LeftMargin { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> RightMargin { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> IsRomanNumerals { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> VerticalPositionStyle VerticalPositionStyle { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> HorizontalPositionStyle HorizontalPositionStyle { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	and now RomanConverter:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> System;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">namespace</span> PageNumberer
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">class</span> RomanConverter
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">int</span>[] values = <span style="color: #0000ff">new</span> <span style="color: #0000ff">int</span>[] { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span>[] numerals = <span style="color: #0000ff">new</span> <span style="color: #0000ff">string</span>[] { &quot;<span style="color: #8b0000">M</span>&quot;, &quot;<span style="color: #8b0000">CM</span>&quot;, &quot;<span style="color: #8b0000">D</span>&quot;, &quot;<span style="color: #8b0000">CD</span>&quot;, &quot;<span style="color: #8b0000">C</span>&quot;, &quot;<span style="color: #8b0000">XC</span>&quot;, &quot;<span style="color: #8b0000">L</span>&quot;, &quot;<span style="color: #8b0000">XL</span>&quot;, &quot;<span style="color: #8b0000">X</span>&quot;, &quot;<span style="color: #8b0000">IX</span>&quot;, &quot;<span style="color: #8b0000">V</span>&quot;, &quot;<span style="color: #8b0000">IV</span>&quot;, &quot;<span style="color: #8b0000">I</span>&quot; };
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToRoman(<span style="color: #0000ff">this</span> <span style="color: #0000ff">int</span> number, <span style="color: #0000ff">bool</span> upper)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">if</span> (number &lt; 0 || number &gt; 3999)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentOutOfRangeException(&quot;<span style="color: #8b0000">number</span>&quot;, &quot;<span style="color: #8b0000">Value must be in the range 0 - 3,999.</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">if</span> (number == 0) <span style="color: #0000ff">return</span> &quot;<span style="color: #8b0000">N</span>&quot;;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            StringBuilder sb = <span style="color: #0000ff">new</span> StringBuilder();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; 13; i++)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                <span style="color: #0000ff">while</span> (number &gt;= values[i])
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                    number -= values[i];
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                    sb.Append(numerals[i]);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">return</span> upper ? sb.ToString() : sb.ToString().ToLower();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<p>
	Finally the test code:</p>
<pre>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> System;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">using</span> Atalasoft.PdfDoc.Generating;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
<span style="color: #0000ff">namespace</span> PageNumberer
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
{
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    <span style="color: #0000ff">class</span> Program
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            PdfGeneratedDocument doc = <span style="color: #0000ff">new</span> PdfGeneratedDocument();
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">string</span> tnr = doc.Resources.Fonts.AddFromFontName(&quot;<span style="color: #8b0000">Times New Roman</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            PageNumberGenerator gen = <span style="color: #0000ff">new</span> PageNumberGenerator(tnr, 10);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            gen.IsRomanNumerals = <span style="color: #0000ff">true</span>;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            gen.HorizontalPositionStyle = HorizontalPositionStyle.Center;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; 10; i++)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                PdfGeneratedPage page = PdfDefaultPages.Letter;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                page.DrawingList.Add(gen.NextPageNumber(page));
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                doc.Pages.Add(page);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            gen.IsRomanNumerals = <span style="color: #0000ff">false</span>;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            gen.HorizontalPositionStyle = HorizontalPositionStyle.Alternating;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            gen.Current = 1;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; 5; i++)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            {
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                PdfGeneratedPage page = PdfDefaultPages.Letter;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                page.DrawingList.Add(gen.NextPageNumber(page));
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
                doc.Pages.Add(page);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
            doc.Save(&quot;<span style="color: #8b0000">numberedpages.pdf</span>&quot;);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
        }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
    }
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
}
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">
</pre>
]]></description>
     <pubDate>Thu, 23 Feb 2012 10:18:52 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/february-2012/working-with-dotpdf-shapes-or-shape-generators]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/april-2012/i-like-the-80s-with-struct-style]]></guid>
     <title><![CDATA[I Like the 80s with Struct Style]]></title>
     <description><![CDATA[<p>
	In this article, I&rsquo;m going to talk about 80s era file formats and ways you can support them in .NET and keep your code sane, safe, and short, but to start, let&rsquo;s talk about data file formats and why they are the way they are or were the way they were.</p>
<p>
	First, let&rsquo;s consider why we even have data files.&nbsp; Persistence of data is one reason, but historically you would frequently see data files built because you couldn&rsquo;t keep the entire dataset in memory.&nbsp; In the dim dark ages, you were lucky if you had virtual memory (I&rsquo;m looking at you, Macintosh System 6 and earlier) or if it was lousy (I&rsquo;m looking at you Windows 3.1 and earlier), so you would try to keep your memory footprint low.&nbsp; The obvious solution is to dump things to a temporary file then read them back in later when you needed them again.&nbsp; The trick is that you want to incur as little overhead as possible, so your reading and writing code had to be simple.&nbsp; A typical data structure might look like this:</p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font style="font-size: 10pt">typedef </font></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">struct</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> t_person </span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">char</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> gender</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">char</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> age</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">char</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> firstname</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">[</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">14</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">];</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">char</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> lastname</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">[</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">16</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">];</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080"><font style="font-size: 10pt">}</font></font></span></b><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> t_person</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p>
	<br />
	OK &ndash; that&rsquo;s a quick, badly-designed structure for representing a person.&nbsp; So how would you write it out?</p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff"><font style="font-size: 10pt">if</font></font></span></b><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">fwrite</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">somePerson</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">1</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">sizeof</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">t_person</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">),</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fp</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">!=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">sizeof</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">t_person</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">))</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> FALSE</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">;</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span></font><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#008000" style="font-size: 10pt">/* fail */</font></span></font></p>
<p>
	<br />
	We like <span style="font-family:courier new,courier,monospace;">fwrite</span>, oh yes we do.&nbsp; So much so that if we have an array of t_person, we might write this routine for dumping it out:</p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff"><font style="font-size: 10pt">int</font></font></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> writePeople</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">t_person </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">people</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">int</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> count</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> FILE </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">fp</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">{</font></font></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">int</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> totalBytes </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> count </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">sizeof</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">t_person</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fwrite</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">people</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> count</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">sizeof</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">t_person</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">),</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fp</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">==</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> totalBytes</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">}</font></font></span></b></p>
<p>
	<br />
	and then you think &ndash; oh dang, I didn&rsquo;t write out how big the array was and&nbsp; then you realize that you&rsquo;re filling a temp file with many heterogeneous types and wouldn&rsquo;t it be better if the file was self identifying?&nbsp; So then you would write code like this:</p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff"><font style="font-size: 10pt">int</font></font></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> writeTag</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">INT32 tag</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> FILE </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">fp</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">{</font></font></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fwrite</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(&amp;</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">tag</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">1</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">sizeof</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">INT32</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">),</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fp</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">==</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">sizeof</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">INT32</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">}</font></font></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff"><font style="font-size: 10pt">int</font></font></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> writePeople</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">t_person </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">person</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">int</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> count</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> FILE </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">fp</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">{</font></font></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(!</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">writeTag</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">kPersonTag</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fp</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">))</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> FALSE</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(!</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">writeTag</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">count</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fp</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">))</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> FALSE</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">int</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> totalBytes </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> count </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">sizeof</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">t_person</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fwrite</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">people</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> count</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">sizeof</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">t_person</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">),</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fp</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">==</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> totalBytes</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">}</font></font></span></b></p>
<p>
	<br />
	and by solving a problem (forgot the array length and didn&rsquo;t identify the type, I&rsquo;ve created several new problems.&nbsp; First of, fwrite was fine to use if all I was writing was characters (this is a lie, by the way), but the moment I write a non-byte, I&rsquo;m now writing the int with the implicit byte ordering of the processor running the code.&nbsp; That means that if the tag is 0x01020304, then on a little endian processor, you will write the following bytes in sequence: 04, 03, 02, 01, but on a big endian processor (such as a 68K), you would write 01, 02, 03, 04.&nbsp; This means that when you inevitably port your code from, say Windows to Macintosh, your reading code (if you use fread) won&rsquo;t work.&nbsp; Ouch.</p>
<p>
	Why did we use fwrite again?&nbsp; Why did that seem like such a good idea?&nbsp; Well, we could write the entire data structure in one shot, one line of code.&nbsp; Otherwise, we would have to write code to write each element out in a platform-neutral way.&nbsp; You&rsquo;re going to have to do that, because two things just entered the equation from C that made your life worse: some compilers take the liberty of changing your structure layout in order to make accessing the elements more efficient.&nbsp; So that lie back there about fwrite being fine with a struct of only characters: if your compiler inserts pad bytes, you&rsquo;re writing more data than you suspect.&nbsp; Dang.&nbsp; Then, when C introduce enumerated values, they left it to the compiler to decide the data type best-suited for holding all the enumerated values.&nbsp; The problem is that some compilers made different decisions than others and so your struct size would be different, depending on the compiler.</p>
<p>
	At this point you realize that writing structs isn&rsquo;t quite so easy, and maybe that job at the garden center is looking a whole lot nicer.&nbsp; Still, this gives you a little historical perspective.</p>
<p>
	Flash forward to current technologies.&nbsp; How can we read these 80&rsquo;s era data structures into C# and not suffer.&nbsp; You could try to set up a struct in C# and play games with struct layout attributes and read the data in in one fell swoop, but trust me, this is not the way to go.&nbsp; If that was bad in the 80&rsquo;s, it&rsquo;s just as bad now.</p>
<p>
	Let&rsquo;s make some assumptions &ndash; first, let&rsquo;s pretend that our data file is in big endian order.&nbsp; Second, let&rsquo;s assume that we already have a class has methods in it like this:</p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff"><font style="font-size: 10pt">public</font></font></span></b><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">class</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> BigEndianReader </span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">bool</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Read</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Stream stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">out</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">ulong</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ul</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">{</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#008000">/* ... */</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt"> </font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">bool</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Read</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Stream stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">out</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">long</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ul</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">{</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#008000">/* ... */</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt"> </font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp; </font></span><font style="font-size: 10pt"><span style="mso-spacerun: yes">&nbsp;</span></font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">bool</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Read</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Stream stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">out</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">uint</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ul</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">{</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#008000">/* ... */</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt"> </font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">bool</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Read</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Stream stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">out</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">int</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ul</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">{</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#008000">/* ... */</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt"> </font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">bool</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Read</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Stream stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">out</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">short</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ul</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">{</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#008000">/* ... */ </font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt"> </font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">bool</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Read</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Stream stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">out</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">ushort</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ul</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">{</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#008000">/* ... */</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">bool</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ReadScalar</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Stream stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Type ft</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">out</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">object</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> o</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">ft </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">==</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">typeof</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">byte</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">))</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">int</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> b </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">ReadByte</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">();</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">b </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">&lt;</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">0</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">false</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">o </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">byte</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">b</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">true</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">ft </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">==</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">typeof</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">sbyte</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">))</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">int</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> b </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">ReadByte</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">();</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">b </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">&lt;</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">0</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">false</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">o </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">sbyte</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">b</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">true</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">ft </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">==</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">typeof</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">int</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">))</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">int</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> i </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">0</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;</font></span><font style="font-size: 10pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(!</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Read</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">out</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> i</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">))</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">false</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">o </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> i</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">true</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#008000" style="font-size: 10pt">// ...</font></span></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">o </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">null</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">false</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">}</font></font></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	This is a set of methods that handle reading in scalar types and one general routine for switching based on the type.&nbsp; This is very straightforward code &ndash; no surprises.</p>
<p>
	Now lets figure out how to read in an array of scalars without knowing it&rsquo;s element type:</p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff"><font style="font-size: 10pt">private</font></font></span></b><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">bool</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ReadIntoArray</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Stream stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Type ft</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> FieldInfo fi</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">object</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> o</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">{</font></font></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">Array arr </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fi</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">GetValue</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">o</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">as</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Array</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">arr </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">==</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">null</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">false</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">Type arrType </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> arr</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">GetType</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">().</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">GetElementType</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">();</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(!</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">IsScalar</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">arrType</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">))</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">false</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">for</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">int</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> i</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">0</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">;</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> i </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">&lt;</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> arr</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">GetLength</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">0</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">);</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> i</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">++)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">object</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> val </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">null</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(!</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">ReadScalar</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> arrType</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">out</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> val</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">))</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">false</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">arr</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">SetValue</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">val</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> i</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">true</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">}</font></font></span></b></p>
<p>
	<br />
	This will read in an array of scalars.&nbsp; How do we know that the array type is a scalar?&nbsp; We have a private predicate IsScalar() that tells us.&nbsp; It essentially checks to see if the type is byte, sbyte, short, ushort, etc.</p>
<p>
	Now this is where the fun part comes in.&nbsp; We write a routine to auto-populate a data structure using reflection:</p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff"><font style="font-size: 10pt">public</font></font></span></b><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">bool</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ReadType</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Stream stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">object</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> o</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">params</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">string</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">[]</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> names</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">{</font></font></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">Type t </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> o</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">GetType</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">();</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">foreach</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">string</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> name </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">in</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> names</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt"><span style="mso-spacerun: yes">&nbsp;</span>FieldInfo fi </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> t</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">GetField</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">name</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">fi </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">==</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">null</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">throw</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ArgumentException</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;unable to find field &quot;</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">+</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> name</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">Type ft </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fi</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">FieldType</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">IsScalar</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">ft</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">))</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">object</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> val </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">null</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(!</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">ReadScalar</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ft</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">out</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> val</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">))</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">false</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">fi</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">SetValue</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">o</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> val</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">else</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">IsArray</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">ft</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">))</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">ReadIntoArray</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> ft</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fi</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> o</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">}</font></font></span></b></p>
<p>
	<br />
	In this routine, we pass in a Stream, an object, and a list of names of fields to be populated.&nbsp; We could also use properties if we wanted, but I&rsquo;m sticking with fields right now.&nbsp; With all this in place, let&rsquo;s set our stage for parsing data from TrueType fonts.&nbsp; Keep in mind that these structures are purely representational and are not part of a good API since the abstraction is wrong.&nbsp; Here is a class that represents the TrueType font header structure:</p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff"><font style="font-size: 10pt">class</font></font></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> TTFontHeader </span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">uint</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> TableVersion</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">uint</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> FontRevision</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">uint</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> CheckSumAdjustment</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">uint</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> MagicNumber</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">ushort</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Flags</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">ushort</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> UnitsPerEm</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">long</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Created</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">long</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Modified</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">short</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> XMin</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">short</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> YMin</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">short</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> XMax</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;</font></span><font style="font-size: 10pt"><span style="mso-spacerun: yes">&nbsp;&nbsp; </span></font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">short</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> YMax</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">ushort</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> MacStyle</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">ushort</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> LowestRecPPEM</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">short</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> FontDirectionHint</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">short</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> IndexToLocFormat</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">short</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> GlyphDataFormat</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> TTFontHeader FromStream</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Stream stm</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt"><span style="mso-spacerun: yes">&nbsp; </span>TTFontHeader fh </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> TTFontHeader</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">();</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(!</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">BigEndianReader</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">ReadType</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fh</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;TableVersion&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;FontRevision&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;CheckSumAdjustment&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;MagicNumber&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;Flags&quot;</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">,</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;UnitsPerEm&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;Created&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;Modified&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;XMin&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;YMin&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;XMax&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;YMax&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;MacStyle&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;LowestRecPPEM&quot;</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">,</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;FontDirectionHint&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;IndexToLocFormat&quot;</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;GlyphDataFormat&quot;</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">))</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">throw</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Exception</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;unable to read TTFont header&quot;</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> fh</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">}</font></font></span></b></p>
<p>
	<br />
	Now I&rsquo;ve got very simple code to read in all the fields.&nbsp; Just to remind you of the hell of the 80&rsquo;s, recall that for any given data structure you may have different versions.&nbsp; For example, the OS/2 metrics table inside TrueType files may include more fields depending on the version.&nbsp; We can work with that by writing code like this:</p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff"><font style="font-size: 10pt">public</font></font></span></b><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> TTOS2WindowsMetrics FromStream</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Stream stm</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">{</font></font></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">ushort</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> version </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">0</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(!</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">BigEndianReader</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Read</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">out</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> version</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">))</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">throw</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Exception</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;failure reading OS/2 version&quot;</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">TTOS2WindowsMetrics met </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> TTOS2WindowsMetrics</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">version</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">);</font></span></b></font><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp; </font></span></span></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">string</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">[]</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> names </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">null</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">switch</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">version</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">case</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">0</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">:</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> names </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> _v0FieldNames</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">;</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">break</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">case</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">1</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">:</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> names </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> _v1FieldNames</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">;</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">break</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">case</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">2</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">:</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">case</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">3</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">:</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">case</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">4</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">:</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> names </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> _v2and3and4Fields</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">;</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">break</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">default</font></span></b><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">:</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">throw</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Exception</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;unexpected OS/2 metrics version&quot;</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(!</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">BigEndianReader</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">ReadType</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">stm</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> met</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> names</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">))</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">throw</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Exception</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;failure reading OS/2 metrics&quot;</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> met</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font color="#000080" style="font-size: 10pt">}</font></font></span></b></p>
<p>
	<br />
	One of the reasons why I like this is that it will fail fast if you rename fields (you unit tested that, right?) and should be highly round-trip testable which should make it easy to catch missed values, typos in strings and so on.&nbsp; Again, this example uses fields for all the data values.&nbsp; This is a decision to model the C structures as directly as possible.&nbsp; They could very easily have been properties or the code code be extended to handle either.&nbsp; When you build appropriate small tools, you can build robust higher level tools for making the mundane easier to do.</p>
]]></description>
     <pubDate>Fri, 04 May 2012 14:06:48 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/april-2012/i-like-the-80s-with-struct-style]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/may-2012/dragon-curve]]></guid>
     <title><![CDATA[Dragon Curve]]></title>
     <description><![CDATA[<p>
	I was looking at the code for the <a href="http://en.wikipedia.org/wiki/Dragon_curve">Dragon Curve</a> and it struck me that this should be an easy fractal to represent in PDF.&nbsp; Even though the curve is usually represented with relative moves and turns which are trivial in PDF, I chose to stay closer to some of the examples in <a href="http://rosettacode.org/wiki/Dragon_curve">Rosetta Code</a> to keep it consistent with their examples, if you wanted to side-by-side them.&nbsp; This is a great basic example on how to use <a href="http://atalasoft.com/products/dotpdf/">DotPdf</a> for generating graphics on a page.</p>
<p>
	The first thing was a class that wraps the Dragon curve code.&nbsp; There is one main entry that returns a PdfPath that represents the curve.&nbsp; You could parameterize it further by exposing length and split.</p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">class</font></span></font><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font style="font-size: 10pt"> Dragon</font></span></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">private</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">double</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> _sqrt2 </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Math</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Sqrt</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">2.0</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">private</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> PdfPath _path</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">private</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">double</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> _angle</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">private</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> PdfPoint _currPoint</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">private</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">void</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Turn</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">double</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> degrees</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">_angle </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">+=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> degrees </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Math</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">PI </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">/</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">180.0</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">private</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">void</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Forward</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">double</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> length</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">_currPoint </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> _currPoint </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">+</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> PdfPoint</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Math</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Cos</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">_angle</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> length</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Math</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Sin</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">_angle</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">)</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> length</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">_path</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">LineTo</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">_currPoint</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">private</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">void</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> MakeDragon</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">double</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> length</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">int</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> split</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">double</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> d</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">if</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">split </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">==</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">0</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">Forward</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">length</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">else</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">length </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">/=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> _sqrt2</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">Turn</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">d </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">45</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">MakeDragon</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">length</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> split </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">-</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">1</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">1</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">Turn</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(-</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">d </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">90</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">MakeDragon</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">length</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> split </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">-</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">1</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">-</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">1</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">Turn</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">d </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">*</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">45</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">public</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> PdfPath MakeDragon</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">IPdfColor color</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> PdfPoint startLocation</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">_angle </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">0</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">_currPoint </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> PdfPoint</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">startLocation</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">_path </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> PdfPath</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">color</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">.75</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt"><span style="mso-spacerun: yes">&nbsp;&nbsp; </span>_path</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">MoveTo</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">_currPoint</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">MakeDragon</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">400</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">12</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">1</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font face="Courier New"><font style="font-size: 10pt">&nbsp;</font></font></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">return</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> _path</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p>
	All that remains is to use this class in the context of a PdfDocument.&nbsp; First, I make a document,&nbsp; then a page, then I place the output of the Dragon class on the page.&nbsp; One thing you&rsquo;ll note is that to make the page, I use the PdfDefaultPages class which is a set of <em>factory properties</em> each of which generates a new page in the size and orientation indicated by its name (I could&rsquo;ve said <a href="http://en.wikipedia.org/wiki/Eponym">eponymous</a> size and orientation, but then I&rsquo;d get a talking to about keeping my writing accessible.&nbsp; Have I mentioned that I love language recently?).</p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><font style="font-size: 10pt"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">static</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">void</font></span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Main</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#8000ff">string</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">[]</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> args</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">{</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">PdfGeneratedDocument doc </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> PdfGeneratedDocument</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">();</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">doc</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">EmbedGeneratedContent </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">false</font></span></b></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">PdfGeneratedPage page </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> PdfDefaultPages</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">LetterLandscape</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">;</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">doc</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Pages</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Add</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">page</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">Dragon dragon </font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">=</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> Dragon</span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">();</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt">page</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">DrawingList</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Add</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">dragon</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">MakeDragon</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">PdfColorFactory</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">FromRgb</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">.8</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">.25</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">.8</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">),</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#0000ff">new</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> PdfPoint</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">250</font></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">,</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"> </span><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#ff8000">250</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">)));</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font style="font-size: 10pt"><span style="mso-spacerun: yes">&nbsp; </span>doc</font></span><font style="font-size: 10pt"><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">.</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'">Save</span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080">(</font></span></b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#808080">&quot;dragon.pdf&quot;</font></span></font><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">);</font></span></b></font></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; background: white">
	<font face="Courier New"><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="font-family: ; color: ; mso-fareast-font-family: 'Times New Roman'"><font color="#000080" style="font-size: 10pt">}</font></span></b></font></p>
<p>
	Seriously, that&rsquo;s it.&nbsp; It&rsquo;s a nice short, sweet example.&nbsp; <a href="http://atalasoft.com/Products/DotPdf/Download/Download-Product">Download DotPdf</a> and run the code &ndash; you get a free trial!</p>
]]></description>
     <pubDate>Mon, 07 May 2012 14:46:56 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/may-2012/dragon-curve]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/june-2012/wow,-it’s-been-quiet]]></guid>
     <title><![CDATA[Wow, It’s Been Quiet]]></title>
     <description><![CDATA[<p>
	Have you heard the crickets?&nbsp; I&rsquo;m not surprised.&nbsp; The one thing you can count on when the blogs run thin is that we&rsquo;re <em>very</em> busy and that there are exciting things on the horizon.&nbsp; I can&rsquo;t talk about those things yet, but I can tell you about another thing that&rsquo;s been taking a lot of my time.</p>
<p>
	One thing you should consider when you are a software engineer is your health.&nbsp; Seriously.&nbsp; Software engineering is a sedentary job.&nbsp; This is unfortunate, but it is what it is.&nbsp; It is then your responsibility to take care of yourself.&nbsp; When you are in good physical condition, you are more relaxed, you sleep better, you think better, etc.&nbsp; But there are times when we are in crunch mode and can&rsquo;t exercise, right?&nbsp; Nonsense.&nbsp; First, crunch time shouldn&rsquo;t exist &ndash; I believe it is the result of poor planning.&nbsp; Second, if you&rsquo;re under the gun, you should absolutely sleep and exercise.&nbsp; You&rsquo;ll introduce fewer bugs.</p>
<p>
	Atalasoft has a lot of runners.&nbsp; We have three people who have run marathons, a couple people who are doing roller derby, and so on.&nbsp; Being active is part of the Atalasoft engineering culture, for sure.&nbsp; Last year, I did the <a href="http://www.coolrunning.com/engine/2/2_3/181.shtml">couch to 5K program</a> and found it worked quite well.&nbsp; I did the routine with two other coworkers, which was nice.&nbsp; This year, I did a crazy thing.&nbsp; I&rsquo;ll fill you in, but first let me give you some background.&nbsp; This is my daughter, Alice:</p>
<p>
	<img src="http://farm8.staticflickr.com/7245/7373687570_79933d9eb3_z.jpg" style="display: block; float: none; margin-left: auto; margin-right: auto" /></p>
<p>
	She is a funny, energetic 9 year-old girl.&nbsp; She also has Down syndrome.&nbsp; It&rsquo;s been a challenge to be a parent to a child with special needs, to say the least.&nbsp; Fortunately, there are organizations all around the world for helping people with Down syndrome and their families as well as their educators.&nbsp; In Massachusetts, we are involved with the <a href="http://www.mdsc.org/">Massachusetts Down Syndrome Congress</a>, which has been invaluable in helping us and other families in the state.&nbsp; I can&rsquo;t imagine trying to navigate through life without their information and guidance.</p>
<p>
	This past spring, they announced that they had secured a handful of slots in the <a href="http://www.falmouthroadrace.com/">Falmouth Road Race</a>.&nbsp; The race is a highly competitive 7 mile race held in August in Falmouth, Massachusetts.&nbsp; The catch?&nbsp; Runners under their name need to raise money for the MDSC.&nbsp; To me this is a slam dunk.&nbsp; So since early March, I have been training to get my distance up to 7 miles.&nbsp; For me, this is no small feat.&nbsp; Even though I did 5K last year, I lost that in the fall and winter due to circumstances that were beyond my control.&nbsp; Fortunately, training has been going well and though I will not run the entire distance (I will be running .75 miles followed by .25 mile walks), I will complete the race.&nbsp; Currently, I&rsquo;m at 5.5 miles and on my last training run, I felt that even if I had to walk mile 6, I could finish the race.&nbsp; This is a nice confidence-building moment.&nbsp; In four more weeks, I should be at the 7.5 mile distance, well-enough past the 7 mile range.&nbsp; <a href="http://mdsc.kintera.org/faf/donorReg/donorPledge.asp?ievent=1024086&amp;lis=1&amp;kntae1024086=E12A1BCEA17548A493B518E742256A16&amp;supId=74124424">Please consider donating</a>, even if you are not a Massachusetts resident.&nbsp; Any donation is tax-deductible and will help parents learn to raise their children to be healthy, self-advocates as well as helping educators learn to be more effective.</p>
]]></description>
     <pubDate>Tue, 26 Jun 2012 12:04:29 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/june-2012/wow,-it’s-been-quiet]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/july-2012/the-importance-of-writing-good-specifications]]></guid>
     <title><![CDATA[The Importance of Writing Good Specifications]]></title>
     <description><![CDATA[<p>
	The message in this blog article is very simple: write good specifications.&nbsp; The word &lsquo;good&rsquo; is problematic as it is terribly broad, so let&rsquo;s narrow it down a little bit.&nbsp; A good specification is simple, clear and unambiguous and when it is impossible to avoid ambiguity, it should describe how to resolve any ambiguity.&nbsp; The <a href="http://www.w3.org/TR/SVG/Overview.html">SVG specification</a> contains a good lesson in how to not do this, which I will talk about in detail.&nbsp; First, let&rsquo;s talk about the various ways that can be used to specify geometrical figures.</p>
<p>
	For most geometric figures, there are multiple ways that they can be specified.&nbsp; For example, a line (infinite) or a line segment can be specified by two points (<em>x<sub>1</sub>, y<sub>1</sub></em>) and (<em>x<sub>2</sub>, y<sub>2</sub></em>).&nbsp; In most applications, this is convenient and compact, but let&rsquo;s consider another way of representing a line:</p>
<p>
	Slope/intercept (from the formula <em>y</em> = <em>mx</em> + <em>b</em>, where <em>m</em> is the slope, <font face="Symbol">D</font><em>x</em>/<font face="Symbol">D</font><em>y</em>, and <em>b</em> i s the y intercept)</p>
<p>
	You should know this well from basic algebra.&nbsp; So we can take that and say that we will represent our line as (<em>m</em>, <em>b</em>).&nbsp; This is nice &ndash; it&rsquo;s more compact than the four points.&nbsp; The problem with it is that <em>m</em> is undefined when the line is vertical.&nbsp; Oops.&nbsp; If we specified slope intercept, we&rsquo;d need a way to deal with that.&nbsp; Maybe a flag that says that when the flag is true, the formula is to be interpreted as <font face="Symbol">D</font><em>y</em>/<font face="Symbol">D</font><em>x</em> and <em>m</em> is the x intercept.&nbsp; OK, that fixes that problem, but it makes the spec more complicated.</p>
<p>
	This can be used to define a line &ndash; what about a segment?&nbsp; How about a starting point and a length?&nbsp; Now our spec is (<em>m</em>, <em>b</em>, <em>f</em>, <em>x<sub>1</sub>, y<sub>1</sub></em>, <em>l</em>).&nbsp; This is also ambiguous, because we don&rsquo;t know which side of the point to extend the length (maybe it&rsquo;s centered).&nbsp; You see what&rsquo;s happening?&nbsp; Something that started relatively simply is just getting worse and worse.</p>
<p>
	Now consider the SVG specification for elliptical arcs &ndash; the parameters that define it are (<em>rx</em>, <em>ry</em>, <font face="Symbol">j,</font> <em>large-arc-flag</em>, <em>sweep-flag</em>, <em>x</em>, <em>y</em>) where <em>rx</em> and <em>ry</em> are the radii of the ellipse, <font face="Symbol">j</font> is the a rotation angle relative to the x-axis, <em>large-arc-flag</em> defines whether to use the large piece of the arc or the small piece, <em>sweep-flag</em> defines the which of two elliptical paths to select that could fit the data, and (x, y) are the end point of the arc.&nbsp; The start point is implicitly defined by previous path.&nbsp; To help you out, here is an illustration from the spec:</p>
<p>
	<img alt="Illustration of flags in arc commands" src="http://www.w3.org/TR/SVG/images/paths/arcs02.png" style="display: block; float: none; margin-left: auto; margin-right: auto" /></p>
<p>
	&nbsp;</p>
<p>
	technically this is a correct way to describe an elliptical arc, but it is wrong in so many ways.&nbsp; First, it is ambiguous.&nbsp; I can provide an ending point and radii for which there are no solutions and if you code up the math to solve for the ellipse, you will only find out about the problem when you need to take the square root of a negative number.&nbsp; No worries, the spec describes what you should do in these cases, in what also turns out to be an ambiguous and overly complicated fashion.&nbsp; Seriously.&nbsp; <a href="http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes">Check it out</a>.&nbsp; It requires an unnecessary wall of math which turns into a wall of code.&nbsp; In addition, if the start and end points are 180 degrees out of phase, there is no large arc &ndash; they&rsquo;re both the same size.&nbsp; Which do you pick?&nbsp; Finally, the x-axis angle, <font face="Symbol">j</font>, is totally redundant since any shape can be contained within a transform.</p>
<p>
	To be generous, there is one and only one reason I can think of for this that it&rsquo;s fairly simple to decide the two points that start and end the arc if you&rsquo;re hand-coding SVG, but the other ambiguities outweigh this benefit in my opinion.</p>
<p>
	Instead, they should use the specification (<em>cx</em>, <em>cy</em>, <em>rx</em>, <em>rx</em>, <font face="Symbol">q</font><sub>1</sub>, <font face="Symbol">q</font><sub>2</sub>, <em>cw</em>), where cx and cy are the coordinates of the center of the ellipse, <em>rx</em> and <em>ry</em> are the radii, <font face="Symbol">q</font><sub>1</sub> and <font face="Symbol">q</font><sub>2</sub> are the start and end angles of the ellipse in degrees, and <em>cw</em> determines if the arc should be drawn clockwise or counterclockwise from <font face="Symbol">q</font><sub>1</sub> to <font face="Symbol">q</font><sub>2</sub>.&nbsp; This spec is simpler to implement and impossible to get incorrect values.&nbsp; You could simplify it further and remove <em>rx</em> and <em>ry</em> and instead use a parent scale transform to set the radii, if you wanted.</p>
<p>
	To a certain extent, I prefer the PDF approach to representing arcs and circles: you don&rsquo;t.&nbsp; In PDF there are only Bezier curves and the specification is very simple.&nbsp; While drawing a Bezier curve is also simple, it can be tricky to do it efficiently.&nbsp; Also, circles can&rsquo;t be represented by Beziers without error.&nbsp; Fortunately, <a href="http://www.tinaja.com/glib/ellipse4.pdf">Don Lancaster has a great article</a> on how to approximate circles and minimize the error.&nbsp; If you use Atalasoft&rsquo;s <a href="http://atalasoft.com/products/dotpdf">DotPdf</a> toolkit, you&rsquo;ll get high-level shapes that implement this for you (as well as SVG-&gt;PDF conversion).&nbsp; On another day, I&rsquo;ll share how I turn an elliptical arc into Beziers.&nbsp; In the meantime, write good specifications!</p>
]]></description>
     <pubDate>Tue, 10 Jul 2012 10:51:03 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/july-2012/the-importance-of-writing-good-specifications]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/october-2012/about-those-enums,-java…]]></guid>
     <title><![CDATA[About those Enums, Java…]]></title>
     <description><![CDATA[<p>
	As you&rsquo;ve seen, we&rsquo;ve released a new product &ndash; <a href="http://atalasoft.com/products/joltimage">JoltImage</a>.&nbsp; This is our foray into the Java world of image processing, something that we&rsquo;ve been contemplating for some time.&nbsp; I will be writing about that experience so that engineers faced with similar problems (porting .NET code to Java) might have a reference.</p>
<p>
	When I started working in Java in 1996, it was a brand new language and working in it was freeing to a certain extent.&nbsp; I found that compared with C or C++, I was able to write far more code with far fewer bugs that I had in the past.&nbsp; Having checked arrays, immutable strings, and garbage collection removed three personal sources of bugs.</p>
<p>
	One thing that it lacked was enumerations.&nbsp; This is something that is, IMHO, vital.&nbsp; The work around was declaring public final values to use or to make singletons.&nbsp; The problem with public finals are the lack of type safety and singletons are more heavyweight than you&rsquo;d like.</p>
<p>
	Before I take a hammer to Java, let&rsquo;s step back and examine the use cases for enumerations:</p>
<p>
	Cardinal values</p>
<p>
	Ordinal values</p>
<p>
	Set elements</p>
<p>
	Cardinal values are effectively atoms &ndash; symbolic names that have no particular meaningful value.&nbsp; Ordinals are symbols that have specific values that have meaning and may or may not have operations on those values.&nbsp; Set elements are either cardinal or ordinal values that need to be contained in a set and have specific set operations (intersection, union, difference, complement, member, etc.).</p>
<p>
	In Java, enums are easiest to use for Cardinal values and appear to be optimized for that.&nbsp; I can do the following declaration:</p>
<p>
	<font face="Courier New" size="2"><font color="#9b00d3">public enum</font> IOPortID {</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; A, B, C, D;</font></p>
<p>
	<font face="Courier New" size="2">}</font></p>
<p>
	&nbsp;</p>
<p>
	<span class="sc0">In this case, I can refer to an IO port very easily by name.&nbsp; Terrific.&nbsp; Now suppose that each of the ports has slightly more meaning. </span></p>
<p>
	<span class="sc0">Let&rsquo;s say that each of those ports is associated with a hardware address.&nbsp; You&rsquo;d LIKE to be able to just associate the address with the symbol.&nbsp; That should be easy, but you can&rsquo;t do that.&nbsp; At least not really.&nbsp; Instead, you have two choices, code that looks like this:</span></p>
<p>
	<font face="Courier New" size="2"><font color="#9b00d3">public enum</font> IOPortID {</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; A, B, C, D;</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; <font color="#9b00d3">final int</font> toHardwareAddress() {</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#9b00d3">switch</font> (this) {</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#9b00d3">case</font> A: <font color="#9b00d3">return</font> 0xaba;</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#9b00d3">case</font> B: <font color="#9b00d3">return</font> 0xabb;</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#9b00d3">case</font> C: <font color="#9b00d3">return</font> 0xabc;</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#9b00d3">case</font> D: <font color="#9b00d3">return</font> 0xabd;</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#9b00d3">default</font>: <font color="#9b00d3">throw new</font> RuntimeException(&ldquo;Illegal IOPortID!&rdquo;);</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; }</font></p>
<p>
	<font face="Courier New" size="2">}</font></p>
<p>
	&nbsp;</p>
<div style="line-height: 1; display: inline; white-space: pre; background: #ffffff; float: none">
	<span class="sc0">or code that looks like this:</span></div>
<p>
	&nbsp;</p>
<p>
	<font face="Courier New" size="2"><font color="#9b00d3">public enum</font> IOPortID {</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; A(0xaba), B(0xabb), C(0xabc), D(0xabd);</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; <font color="#9b00d3">private</font> <font color="#9b00d3">int</font> _value;</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; <font color="#9b00d3">private</font> IOPortID(<font color="#9b00d3">int</font> value) { _value = value; }</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; <font face="Courier New" size="2"><font color="#9b00d3">public </font></font><font color="#9b00d3">static</font> IOPortID fromValue(<font color="#9b00d3">int</font> value)</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; {</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#9b00d3">if</font> (value == A._value) <font color="#9b00d3">return</font> A;</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#9b00d3">if</font> (value == B._value) <font color="#9b00d3">return</font> B;</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#9b00d3">if</font> (value == C._value) <font color="#9b00d3">return</font> C;</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#9b00d3">if</font> (value == D._value) <font color="#9b00d3">return</font> D;</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#9b00d3">throw new</font> IllegalArgumentException(&ldquo;unknown hardware address &ldquo; + value);</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; }</font></p>
<p>
	<font face="Courier New" size="2">}</font></p>
<p>
	Either implementation is bad.&nbsp; The first one might be slightly better in that I&rsquo;ve decoupled the port ID value from the port ID symbol and made that particular method accessible only within the namespace.&nbsp; In both cases, I&rsquo;ve had to put in a stack of boilerplate code which is a bad <a href="http://en.wikipedia.org/wiki/Code_smell">code smell</a>.&nbsp; I will say that because Java does not dictate how many members you put into an enum, you could very well put in any number of scalar dimensions or references to other classes.&nbsp; For example, you could make an enum that encapsulates longitude and latitude and represents major cities.</p>
<p>
	And herein is the problem with Java enumerated values: they are not enumerated values.&nbsp; They are singleton classes.&nbsp; When I declare an enum as in the very first example, I end up with 4 classes constructed, A, B, C, and D.&nbsp; Don&rsquo;t believe me?&nbsp; Add a setValue() method to each of the above and you can mutate your enum.&nbsp; Yikes.&nbsp; I can think of a few reasons why you might want to do this, but they&rsquo;re all hacks on top of a bad base model.</p>
<p>
	One of the other handy use cases in enums is to represent bit flags for settings.&nbsp; This is frequently used in software &ndash; for example, the permissions in a PDF file is represented by a 32-bit integer holding a set of bit flags.&nbsp; The prescribed method is to use <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/util/EnumSet.html">EnumSet</a>.&nbsp; EnumSet has two main problems with it which are intimately entwined: it is neither blittable nor is it immutable.&nbsp; Let me explain &ndash; a blittable type is any type that is bit-for-bit copied by an assignment.&nbsp; Scalars (int, char, float, etc.) are blittable.&nbsp; Class instances are not blittable, they are copied.&nbsp; Since Enums and EnumSets are classes, they are not blittable.&nbsp; This means that if they are mutable (and Enums can be and EnumSets are), then we have to be very careful about how they are used.&nbsp; For example, if I design an abstract class that needs to return an EnumSet of all operations that it supports, I need to either prescribe that the implementation always return a new EnumSet (bad idea &ndash; I can&rsquo;t trust all my implementors) or wrap each call to the abstract method in another method that does a EnumSet.copyOf().&nbsp; This is cumbersome and error prone and is necessary because EnumSet is fundamentally broken.&nbsp; remove() and removeAll mutate the set &ndash; this is bad.&nbsp; Instead, their should be the methods intersect(other), union(other), difference(other), complement(), which do the actual set operations and return a new EnumSet with the appropriate types and there should be no mutators.&nbsp; This way instead of writing this code:</p>
<p>
	<font face="Courier New" size="2"><font face="Courier New" size="2"><font color="#9b00d3">public </font></font><font color="#9b00d3">final boolean</font> has1DOtherThanCode39(EnumSet&lt;Symbologies&gt; sym)</font></p>
<p>
	<font face="Courier New" size="2">{</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; EnumSet&lt;Symbologies&gt; set = EnumSet.copyOf(sym); <font color="#008000">// have to copy!</font></font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; set.removeAll(Symbologies.all2D());</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; set.remove(Symbologies.CODE_39);</font></p>
<p>
	<font face="Courier New" size="2">&nbsp;&nbsp; <font color="#9b00d3">return</font> !set.isEmpty();</font></p>
<p>
	<font face="Courier New" size="2">}</font></p>
<p>
	I could write this:</p>
<p>
	<font face="Courier New" size="2"><font color="#9b00d3">return</font> !sym.difference(Symbologies.all2D().union(Symbologies.CODE_39)).isEmpty();</font></p>
<p>
	or the equivalent in .NET</p>
<p>
	<font face="Courier New" size="2"><font color="#9b00d3">return</font> (sym &amp; ~(Symbologies.All2D | Symbologies.Code39)) != 0;</font></p>
<p>
	The requirement of the copyOf() is to prevent us from side-effecting the input, since it is passed by reference.&nbsp; This is an easy thing to forget which is a bug waiting to happen.&nbsp; If we left out the copyOf() call, we would be side-effecting the caller&rsquo;s copy which in the case of this particular operation will not always be noticeable.&nbsp; Not cool.&nbsp; In addition, if EnumSet were immutable, then we would be allocating 3 EnumSet objects that would get thrown away immediately (probably their reason for making them mutable in the first place).</p>
<p>
	So we can see that the Java Enum is a class and not actually an enum and when any case beyond simple cardinals is needed (which in my experience is about 3/4 of the time), the programmer is required to use boilerplate code which is error prone.&nbsp; Finally, the use of EnumSets is cumbersome as well as requiring the client to understand the consequences of having a mutable class, although to its credit, EnumSet will scale well beyond 64 members.&nbsp; By contrast, the .NET enum is a scalar (and blittable), and is trivial to use in all the common cases and only starts to be a leaky abstraction when the use case is inappropriate for an enum and more appropriate for an actual class.</p>
]]></description>
     <pubDate>Tue, 09 Oct 2012 13:23:25 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/october-2012/about-those-enums,-java…]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/october-2012/don’t-do-eclipse-headless-builds-ever]]></guid>
     <title><![CDATA[Don’t Do Eclipse Headless Builds Ever]]></title>
     <description><![CDATA[<p>
	We standardized on using Eclipse for Java development for a few reasons, not the least of which was the having <a href="http://www.microsoft.com/en-us/download/details.aspx?id=4240">Team Explorer Anywhere</a> integrated.&nbsp; This was a key feature for us since we use TFS for our regular source control and would prefer to not have another infrastructure system, if possible.</p>
<p>
	Since our shop uses continuous integrated and have all our releases built by automation, we needed to build the Eclipse projects on our own system.&nbsp; If you search for &ldquo;eclipse headless build&rdquo; you will find a number of hits on how to do this.&nbsp; They work.&nbsp; Sometimes.&nbsp; Sort of.&nbsp; We found a couple things &ndash; we can&rsquo;t check in the .metadata folder since it stores absolute paths and one particular engineer&rsquo;s .metadata folder won&rsquo;t necessarily work on the build machine or any other engineer&rsquo;s machine.&nbsp; So we kept a private copy on the build server with the provision that if you added a new sub project, it would be necessary to update the .metadata folder on the build server (and on engineering machines).&nbsp; We found that even with that, builds were flakey.&nbsp; They worked most of the time, but not all the time.&nbsp; By adding a call to refresh the projects before the headless build, we found that we could get a more reliable build.&nbsp; Then we had a new project added that didn&rsquo;t really change the build order on the engineering machines, but it was causing <em><strong>errors on the build server that didn&rsquo;t halt the build</strong></em>.&nbsp; We only found out about them by reading the logs and finding out that later in the build obfuscation was failing.&nbsp; Interestingly enough, the java compiler was spouting errors, but was writing .class files that were technically correct but would never load or run (the compiler injected throws in all the constructors).</p>
<p>
	Long story short: <strong>Don&rsquo;t Do Headless Builds with Eclipse</strong>.&nbsp; They may work in simple projects, but will ultimately fail in the worst possible way: generating bad code and not failing the build.</p>
<p>
	So what do we do?&nbsp; All our builds are run from CruiseControl which then fires up NAnt tasks.&nbsp; When we added Java, we kept the same infrastructure but now fire off Ant tasks to do more Java specific things.&nbsp; First, I broke down a project build into 5 tasks (there&rsquo;s actually a 6th, but I haven&rsquo;t integrated it in this build step fully yet):</p>
<ol>
	<li>
		validate</li>
	<li>
		wipe previous output (not technically necessary, but I like to make sure the environment is clean)</li>
	<li>
		compile</li>
	<li>
		make jar</li>
	<li>
		obfuscate</li>
</ol>
<p>
	With this, I added one file to the global workspace and one file to each project.&nbsp; The global file is a csv that contains a project directory name on each line (with the notion that there may be other information later on each line), then I loop over it with a NAnt foreach (this implies that the file is in build order):</p>
<blockquote>
	<p>
		<font face="Courier New">&lt;foreach item=&quot;Line&quot; in=&quot;ProjectList.csv&quot; property=&quot;buildDirName&quot;&gt;</font></p>
</blockquote>
<p>
	Then I set up some properties including the .classpath&nbsp; file, the src folder, the bin folder and so on.</p>
<p>
	<strong>Validation </strong>&ndash; I want to make sure that each project folder really is intended to be a project.&nbsp; There should be a .classpath and a file I call ProjectManifest.xml.&nbsp; It don&rsquo;t actually contain anything yet, but in the future, there may be project specific properties set in this file so that there need not be as much logic and special cases in the actual build script.</p>
<p>
	<strong>Wipe Previous Output </strong>&ndash; this is easy, just a delete task on the bin folder.</p>
<p>
	<strong>Compile</strong> &ndash; this is somewhat complicated.&nbsp; I wrote an embedded C# script in NAnt that parses the .classpath file and turns it into a string suitable for a command line option to the java compiler.&nbsp; Here&rsquo;s the code, which works well enough:</p>
<blockquote>
	<p>
		<font face="Courier New">&lt;script language=&quot;C#&quot; prefix=&quot;pathmunge&quot;&gt;<br />
		&nbsp; &lt;references&gt;<br />
		&nbsp;&nbsp;&nbsp; &lt;include name=&quot;System.Xml.dll&quot; /&gt;<br />
		&nbsp; &lt;/references&gt;<br />
		&nbsp; &lt;imports&gt;<br />
		&nbsp;&nbsp;&nbsp; &lt;import namespace=&quot;System.IO&quot; /&gt;<br />
		&nbsp;&nbsp;&nbsp; &lt;import namespace=&quot;System.Collections.Generic&quot; /&gt;<br />
		&nbsp;&nbsp;&nbsp; &lt;import namespace=&quot;System.Xml&quot; /&gt;<br />
		&nbsp;&nbsp;&nbsp; &lt;import namespace=&quot;System.Xml.Serialization&quot; /&gt;<br />
		&nbsp; &lt;/imports&gt;<br />
		&nbsp; &lt;code&gt;<br />
		&nbsp;&nbsp;&nbsp; &lt;![CDATA[<br />
		&nbsp;&nbsp;&nbsp; [Function(&quot;to-class-path&quot;)]<br />
		&nbsp;&nbsp;&nbsp; public static string ToClassPath(string projectDir, string dotClassPath)<br />
		&nbsp;&nbsp;&nbsp; {<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;ClassPathEntry&gt; paths = GetPaths(dotClassPath);<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (paths == null)<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new Exception(&quot;unable to find class path entries.&quot;);<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ToClassPath(paths, projectDir);<br />
		&nbsp;&nbsp;&nbsp; }<br />
		&nbsp;&nbsp;&nbsp;<br />
		&nbsp;&nbsp;&nbsp; private static List&lt;ClassPathEntry&gt; GetPaths(string dotClassPath)<br />
		&nbsp;&nbsp;&nbsp; {<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using(TextReader reader = new StreamReader(dotClassPath)) {<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlSerializer serializer = new XmlSerializer(typeof(ClassPath));<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ClassPath cp = (ClassPath)serializer.Deserialize(reader);<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (cp == null) return null;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return cp.Paths;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
		&nbsp;&nbsp;&nbsp; }<br />
		&nbsp;&nbsp;&nbsp;<br />
		&nbsp;&nbsp;&nbsp; private static string ToClassPath(List&lt;ClassPathEntry&gt; list, string projectDir)<br />
		&nbsp;&nbsp;&nbsp; {<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StringBuilder sb = new StringBuilder();<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach(ClassPathEntry entry in list)<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string pathPart = null;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch (entry.Kind)<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;lib&quot;:<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pathPart = projectDir + entry.Path;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;src&quot;:<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (entry.Path == &quot;src&quot;) continue;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pathPart = projectDir + entry.Path + @&quot;\bin&quot;;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default:<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (pathPart != null)<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (sb.Length &gt; 0 &amp;&amp; sb[sb.Length - 1] != &#39;;&#39;) sb.Append(&#39;;&#39;);<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sb.Append(pathPart);<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return sb.ToString();<br />
		&nbsp;&nbsp;&nbsp; }<br />
		&nbsp;&nbsp;&nbsp;<br />
		&nbsp;&nbsp;&nbsp; [Serializable()]<br />
		&nbsp;&nbsp;&nbsp; public class ClassPathEntry {<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private string _kind;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [System.Xml.Serialization.XmlAttribute(&quot;kind&quot;)]<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string Kind { get { return _kind; } set { _kind=value; } }<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private string _path;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [System.Xml.Serialization.XmlAttribute(&quot;path&quot;)]<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string Path { get { return _path; } set { _path = value; } }<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private bool _combineaccessrules;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [System.Xml.Serialization.XmlAttribute(&quot;combineaccessrules&quot;)]<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public bool CombineAccessRules { get { return _combineaccessrules; } set { _combineaccessrules = value; } }<br />
		&nbsp;&nbsp;&nbsp; }<br />
		&nbsp;&nbsp;&nbsp; [Serializable()]<br />
		&nbsp;&nbsp;&nbsp; [System.Xml.Serialization.XmlRootAttribute(&quot;classpath&quot;, Namespace = &quot;&quot;, IsNullable = false)]<br />
		&nbsp;&nbsp;&nbsp; public class ClassPath<br />
		&nbsp;&nbsp;&nbsp; {<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private List&lt;ClassPathEntry&gt; _paths = new List&lt;ClassPathEntry&gt;();<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [XmlElement(&quot;classpathentry&quot;)]<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public List&lt;ClassPathEntry&gt; Paths { get { return _paths; } set { _paths = value; } }<br />
		&nbsp;&nbsp;&nbsp; }<br />
		&nbsp;&nbsp;&nbsp; ]]&gt;<br />
		&nbsp; &lt;/code&gt;<br />
		&lt;/script&gt;</font></p>
</blockquote>
<p>
	You can see that I leverage the Xml serializer to get the information that I need.&nbsp; My first job after writing the compile-java task was to verify that a compiler error would fail the build appropriately.&nbsp; It does.&nbsp; Here is the compile-java task:</p>
<blockquote>
	<p>
		<font face="Courier New">&lt;!-- compile-java - compiles a single java project<br />
		&nbsp; this needs to have Dir.CurrentJavaSrc set<br />
		--&gt;<br />
		&lt;target name=&quot;compile-java&quot; &gt;<br />
		&nbsp; &lt;echo message =&quot;Compiling ${CurrentJavaProject}&quot; /&gt;<br />
		&nbsp; &lt;if test=&quot;${not file::exists(File.DotClassPath)}&quot; &gt;<br />
		&nbsp;&nbsp;&nbsp; &lt;fail message=&quot;compile-java: bad project structure - looking for ${File.DotClassPath}&quot;/&gt;<br />
		&nbsp; &lt;/if&gt;<br />
		&nbsp; &lt;property name=&quot;JREMainJars&quot; value=&quot;${environment::get-variable(&#39;JAVA_HOME&#39;)}\jre\lib\*&quot; /&gt;<br />
		&nbsp; &lt;property name=&quot;JREExtJars&quot; value=&quot;${environment::get-variable(&#39;JAVA_HOME&#39;)}\jre\lib\ext\*&quot; /&gt;<br />
		&nbsp; &lt;property name=&quot;DerivedClassPath&quot; value=&quot;${pathmunge::to-class-path(Dir.Build, File.DotClassPath)};${JREMainJars};${JREExtJars}&quot; /&gt;<br />
		&nbsp; &lt;echo message=&quot;initial class path - ${DerivedClassPath}&quot; /&gt;<br />
		&nbsp; &lt;property name=&quot;ant.commands&quot; value=&quot;-Dcompile-classpath=${quote}${DerivedClassPath}${quote} -Dcompile-srcpath=${quote}${Dir.CurrentJavaSrc}${quote} -Dcompile-binpath=${quote}${Dir.CurrentJavaBin}${quote}&quot; /&gt;<br />
		&nbsp; &lt;property name=&quot;ant.task&quot; value=&quot;compile-project&quot; /&gt;<br />
		&nbsp; &lt;call target =&quot;ant&quot; /&gt;<br />
		&lt;/target&gt;</font></p>
</blockquote>
<p>
	And the actual Ant task is straight forward:</p>
<blockquote>
	<p>
		<font face="Courier New">&lt;target name=&quot;compile-project&quot;&gt;<br />
		&nbsp; &lt;echo message=&quot;compiling with srcpath ${compile-srcpath} binpath ${compile-binpath} classpath ${compile-classpath}&quot; /&gt;<br />
		&nbsp; &lt;javac srcdir=&quot;${compile-srcpath}&quot; destdir=&quot;${compile-binpath}&quot; classpath=&quot;${compile-classpath}&quot; /&gt;<br />
		&lt;/target&gt;</font></p>
</blockquote>
<p>
	The only other missing piece is how we invoke ant:</p>
<blockquote>
	<p>
		<font face="Courier New">&nbsp; &lt;target name=&quot;ant&quot;&gt;<br />
		&nbsp; &lt;exec program=&quot;ant.bat&quot;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; basedir=&quot;${Dir.Ant}\bin&quot;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; workingdir=&quot;${Dir.Build}&quot;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output=&quot;${Progress.Log.File}&quot;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; append=&quot;true&quot;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeout=&quot;7200000&quot;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; verbose=&quot;true&quot;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; failonerror=&quot;true&quot;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; commandline=&quot;-buildfile ${quote}${Dir.Build}\JavaImageAnt.xml${quote} ${ant.commands} ${ant.task}&quot; /&gt;<br />
		&nbsp; &lt;property name=&quot;ant.commands&quot; value=&quot;&quot; /&gt;<br />
		&lt;/target&gt;</font></p>
</blockquote>
<p>
	Oh and ${quote} is used to get an embedded double-quote into a string&nbsp; <font face="Courier New">&lt;property name=&quot;quote&quot; value=&#39;&quot;&#39; /&gt;</font>.</p>
<p>
	<strong>Jar</strong> &ndash; jar is similar to compile.&nbsp; We need the bin directory to pass in and then invoke an Ant task to build the jar file.&nbsp; This is complicated only by the one project that has to have a few external jar&rsquo;s combined into it, so one project gets handled with a special case Ant task.&nbsp; Every project gets a jar even though unit test projects don&rsquo;t strictly need them.</p>
<p>
	<strong>Obfuscate</strong> &ndash; the obfuscation task is nearly identical.&nbsp; At present, all our jars get obfuscated with the same settings using <a href="http://www.zelix.com/klassmaster/">Zelix Klassmaster</a>.&nbsp; We skip the obfuscate step on unit tests as we don&rsquo;t need them and the dependencies would be unusual.</p>
<p>
	There are a number of ways that this type of build automation could be done &ndash; for example, keeping a completely separate ant file that handles the build entirely.&nbsp; In an ideal world, the build would be done by the same system as an engineering workstation, but since that isn&rsquo;t currently possible, we strike a balance to get the build as automatic as possible.&nbsp; In theory, we should be able to analyze all the .classpath files and intuit the build order and this might be a good step for the future.</p>
]]></description>
     <pubDate>Mon, 29 Oct 2012 10:46:36 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/october-2012/don’t-do-eclipse-headless-builds-ever]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/november-2012/what-is-partial-function-application]]></guid>
     <title><![CDATA[What is Partial Function Application?]]></title>
     <description><![CDATA[<p>
	I&rsquo;m going to talk about Partial Function Application in F# and show how you can simulate that (to a degree) in C#.</p>
<p>
	Let&rsquo;s start with a function to calculate quadratic of the form a<em>x</em><sup>2</sup> + b<em>x</em> + c:</p>
<pre class="code">
<span style="color: blue">let </span>quadratic a b c x =
    a * x * x + b * x + c</pre>
<p>
	This is pretty straight-forward &ndash; it just rips through the math and you can see that it works:</p>
<pre class="code">
&gt; quadratic 4.0 3.0 3.0 0.0;;

val it : float = 3.0

&gt; quadratic 4.0 3.0 3.0 1.0;;

val it : float = 10.0

&gt; quadratic 4.0 3.0 3.0 2.0;;

val it : float = 25.0</pre>
<p>
	The cool thing is that you don&rsquo;t have to pass all of the arguments in to quadratic.&nbsp; If you leave off arguments from the end to the front, what you get back is a function that can be applied to the arguments that you left off.&nbsp; What happens is that the arguments you <em>do</em> supply get bound to the parameter names, but the rest still need to be done.&nbsp; I can rework my example to save some typing:</p>
<pre class="code">
<span style="color: blue">let </span>q1 = quadratic 4.0 3.0 3.0
</pre>
<pre class="code">
&gt; q1 0.0;;
val it : float = 3.0

&gt; q1 1.0;;

val it : float = 10.0

&gt; q1 2.0;;

val it : float = 25.0</pre>
<p>
	Moreover, I can define other functions in terms of quadratic.&nbsp; For example, one form of linear function is a quadratic with a = 0:</p>
<pre class="code">
<span style="color: blue">let </span>linear = quadratic 0.0
</pre>
<p>
	Nifty.&nbsp; Now how do we do this in C#?&nbsp; To do this, you need to think about what&rsquo;s happening.&nbsp; When you invoke a function without its full complement of arguments, the compiler goes through an act called &ldquo;binding&rdquo; wherein the supplied argument values are permanently tied to the parameter names.&nbsp; In Lisp or Scheme (and F# is a cousin of these languages), this is often done by creating an &ldquo;environment&rdquo; which is a collection of bounds symbols and their values.&nbsp; We can do this by representing a function as a delegate (which contains an optional reference to a class) and using the class itself as the environment.</p>
<p>
	Here&rsquo;s the quadratic code &ldquo;ported&rdquo; to C#:</p>
<pre class="code">
<span style="color: blue">public class </span><span style="color: #2b91af">Quadratic
</span>{
&nbsp;&nbsp;&nbsp; <span style="color: blue">private double </span>_a, _b, _c;
&nbsp;&nbsp;&nbsp; <span style="color: blue">private </span>Quadratic(<span style="color: blue">double </span>a, <span style="color: blue">double </span>b, <span style="color: blue">double </span>c)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _a = a;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _b = b;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _c = c;
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; <span style="color: blue">private </span>Quadratic(<span style="color: blue">double </span>a, <span style="color: blue">double </span>b) : <span style="color: blue">this</span>(a, b, 0.0) { }
&nbsp;&nbsp;&nbsp; <span style="color: blue">private </span>Quadratic(<span style="color: blue">double </span>a) : <span style="color: blue">this</span>(a, 0.0, 0.0) { }
&nbsp;&nbsp;&nbsp; <span style="color: blue">public static double </span>Value(<span style="color: blue">double </span>a, <span style="color: blue">double </span>b, <span style="color: blue">double </span>c, <span style="color: blue">double </span>x)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return </span>a * x * x + b * x + c;
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; <span style="color: blue">private double </span>_f1(<span style="color: blue">double </span>x) { <span style="color: blue">return </span>Value(_a, _b, _c, x); }
&nbsp;&nbsp;&nbsp; <span style="color: blue">public static </span><span style="color: #2b91af">Func</span>&lt;<span style="color: blue">double</span>, <span style="color: blue">double</span>&gt; F(<span style="color: blue">double </span>a, <span style="color: blue">double </span>b, <span style="color: blue">double </span>c)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Quadratic </span>q = <span style="color: blue">new </span><span style="color: #2b91af">Quadratic</span>(a, b, c);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return </span>q._f1;
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; <span style="color: blue">private double </span>_f2(<span style="color: blue">double </span>c, <span style="color: blue">double </span>x) { <span style="color: blue">return </span>Value(_a, _b, c, x); }
&nbsp;&nbsp;&nbsp; <span style="color: blue">public static </span><span style="color: #2b91af">Func</span>&lt;<span style="color: blue">double</span>, <span style="color: blue">double</span>, <span style="color: blue">double</span>&gt; F(<span style="color: blue">double </span>a, <span style="color: blue">double </span>b)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Quadratic </span>q = <span style="color: blue">new </span><span style="color: #2b91af">Quadratic</span>(a, b);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return </span>q._f2;
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; <span style="color: blue">private double </span>_f3(<span style="color: blue">double </span>b, <span style="color: blue">double </span>c, <span style="color: blue">double </span>x) { <span style="color: blue">return </span>Value(_a, b, c, x); }
&nbsp;&nbsp;&nbsp; <span style="color: blue">public static </span><span style="color: #2b91af">Func</span>&lt;<span style="color: blue">double</span>, <span style="color: blue">double</span>, <span style="color: blue">double</span>, <span style="color: blue">double</span>&gt; F(<span style="color: blue">double </span>a)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Quadratic </span>q = <span style="color: blue">new </span><span style="color: #2b91af">Quadratic</span>(a);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return </span>q._f3;
&nbsp;&nbsp;&nbsp; }

}

</pre>
<p>
	What I&rsquo;ve done is hidden the environment for the function in a private constructor for the class Quadratic.&nbsp; I implemented the actual quadratic function with the static method Value.&nbsp; In the first flavor of F, I take 3 arguments and by newing up a Quadratic, I have bound the values into the environment.&nbsp; _f1 only takes x as its argument and uses _a, _b, and _c from the environment to calculate the quadratic.&nbsp; In every subsequent flavor of F, I drop an argument.</p>
<p>
	I&rsquo;m not saying that this is what F# is actually doing under the hood.&nbsp; There are other ways to get the same behavior, but they&rsquo;re all fairly similar.&nbsp; For example, the F# compiler could just be writing a new function on the fly with the bound values being constants in the IL.&nbsp; What happens is still the same; it&rsquo;s just that the individual IL instructions become the environment instead of a class object.&nbsp; Similarly, the code above could have used lambda expressions instead of the _f functions and then the lambda expression would have captured the arguments instead of the class:</p>
<pre class="code">
<span style="color: blue">public static </span><span style="color: #2b91af">Func</span>&lt;<span style="color: blue">double</span>, <span style="color: blue">double</span>&gt; F(<span style="color: blue">double </span>a, <span style="color: blue">double </span>b, <span style="color: blue">double </span>c)

{
&nbsp;&nbsp;&nbsp; <span style="color: blue">return </span>x =&gt; Value(a, b, c, x);

}</pre>
<p>
	Looking at the C# code, you should be asking yourself why on earth you would want to do this in C#.&nbsp; You might want to keep in mind that class encapsulation is a way of representing <a href="http://en.wikipedia.org/wiki/Closure_(computer_science)">closures</a> rather than the day-to-day business logic of your application.&nbsp; Another case is when you have the task of porting F# code to another platform.&nbsp; In our managed version of dotImage, I made heavy use of partial function application in order to make it easier for me to write generic functions to operate on different pixel formats.&nbsp; It made my code a lot easier to read, maintain, and debug.&nbsp; When I ported this to Java in JoltImage, I could have written the code without using this notion.&nbsp; I was sorely tempted since at present Java doesn&rsquo;t have delegates or lambda expressions in the way that C# does.&nbsp; Because of this, I made an private abstract base class that had the method I wanted to expose and then had a subclass for each pixel format that had a constructor that parameterized the environment.</p>
]]></description>
     <pubDate>Mon, 19 Nov 2012 11:30:52 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/november-2012/what-is-partial-function-application]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/november-2012/jargon]]></guid>
     <title><![CDATA[Jargon]]></title>
     <description><![CDATA[<p>
	Last blog, I wrote about using C# to get some of the benefits of F# <a href="http://atalasoft.com/blogs/stevehawley/november-2012/what-is-partial-function-application">partial function application</a>.&nbsp; In submitting the blog, I was asked by <a href="http://atalasoft.com/company/bios">Rick C.</a> about the phrase &ldquo;newing up&rdquo;.&nbsp; That got me thinking about the jargon we use day to day and how it comes to be.</p>
<p>
	When I was in high school, I did a small amount of electronics work with my dad.&nbsp; He introduced me to <a href="http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_616690_-1">perfboard</a>, which we used for making small circuits by using a wiring pen to make circuits &ndash; bread-boarding he called it.&nbsp; From that point on, I had internalized the jargon.&nbsp; I never really thought about it much &ndash; it was just a word.&nbsp; It&rsquo;s kind of like how most people don&rsquo;t think about the word &lsquo;handicapped&rsquo; which derives from a lottery game called &ldquo;<a href="http://www.snopes.com/language/offense/handicap.asp">hand in cap</a>&rdquo;.&nbsp; My after school job was working at Bell Laboratories for <a href="http://en.wikipedia.org/wiki/Max_Mathews">Max Mathews</a> as a violin builder.&nbsp; The necks of the violins were made from glued-up pieces of poplar.&nbsp; Max sent me to the Bell Labs stock room with a shopping list of things I&rsquo;d need.&nbsp; The list included &ldquo;bread boards,&rdquo; which I found in the stock room.&nbsp; They were exactly that: bread boards.&nbsp; Large wooden boards for rolling out bread dough and which were repurposed by electrical engineers for making prototypes.&nbsp; In my case, I cut them up and, after much carving and other work, turned them into the final product.</p>
<p align="center">
	<a href="http://www.flickr.com/photos/_plinth_/4651368848/" title="Max Mathews Violin by _plinth_, on Flickr"><img alt="Max Mathews Violin" height="500" src="http://farm5.staticflickr.com/4069/4651368848_a27cc22ba6.jpg" width="351" /></a></p>
<p align="center">
	<em><font size="2">Yup, that&rsquo;s me circa 1982.</font></em></p>
<p>
	And in software engineering we make up jargon all the time.&nbsp; We use metaphor, make up new words, and repurpose old words.&nbsp; We talk about visitors, enumerators, events, and so on deftly.&nbsp; Sometimes the origin isn&rsquo;t always clear.&nbsp; My friend <a href="http://www.red-bean.com/jimb">Jim Blandy</a> was given a task to port the text editor <a href="http://doc.cat-v.org/plan_9/4th_edition/papers/sam/">sam</a> and was trying to figure out some of the code.&nbsp; Completely out of context, he asked &ldquo;Hey Steve, what&rsquo;s a rasp?&rdquo;&nbsp; I answered simply, &ldquo;a file with holes in it.&rdquo;&nbsp; This was a forehead-slapping moment which Jim no doubt punctuated with a lot of laughter.&nbsp; He had been trying to work out the meaning of the <a href="http://texteditors.org/cgi-bin/wiki.pl?action=browse&amp;diff=1&amp;id=Jim&amp;revision=1">Rasp</a> struct, which was intended to be a representation of a partial file &ndash; a literal file with holes.</p>
<p>
	And so we come back to the phrase &ldquo;to new up&rdquo;.&nbsp; I consulted a friend of mine who is a dictionary researcher was unable to shed deeper light on the origin of the phrase beyond the earliest I&rsquo;d heard it which was in 2008, spoken by Anders Hejlsberg at the PDC 2008 conference as a substitute for the word &ldquo;instantiate&rdquo;.&nbsp; The first I saw the keyword &lsquo;new&rsquo; in a programming language was in Pascal, but compared to a typical object-oriented implementation of operator new, the Pascal&rsquo;s version is little more than syntactic sugar giving the language type-safe memory allocation.&nbsp; I had expected it to be an older keyword, considering that the <a href="http://ahdictionary.com/word/search.html?q=new&amp;submit.x=35&amp;submit.y=26">English word &lsquo;new&rsquo;</a> is very old, but didn&rsquo;t find earlier programming languages that use it.&nbsp; Heard it earlier than that?&nbsp; By all means, let me know.</p>
]]></description>
     <pubDate>Mon, 19 Nov 2012 16:23:39 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/november-2012/jargon]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/december-2012/merry-christmas-and-happy-holidays-from-atalasoft]]></guid>
     <title><![CDATA[Merry Christmas and Happy Holidays from Atalasoft]]></title>
     <description><![CDATA[<p>
	For the last several years, we&rsquo;ve hosted a Secret Docubot event at Atalasoft.&nbsp; This year, we combined the annual Docubot festivities with a bacon day.&nbsp; Now as I sit back at my desk, trying to concentrate in the face of a food coma, I thought I&rsquo;d present you with some pictures I took during the festivities:</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=c07da319-e6ab-461d-8608-f6fa056de4b2"><img alt="012" border="0" height="484" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=7df42d88-dfd7-4a7f-a504-98b386c3af50" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="012" width="644" /></a></p>
<p align="center">
	Hi!&nbsp; I&rsquo;m bacon!</p>
<p>
	&nbsp;</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=c4f6319a-31e2-448d-865f-b7bc1884dba3"><img alt="002" border="0" height="484" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=fe3c926e-0ecc-41dd-bffd-8563e6d8e8eb" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="002" width="644" /></a></p>
<p align="center">
	We bought a grill to keep in the office.&nbsp; This one is much larger.&nbsp; It&rsquo;s loaded up with two pounds of thick cut pepper bacon from <a href="http://www.smokehouse.com">Burger&rsquo;s Smokehouse</a>.</p>
<p align="center">
	By the way, their Cajun Steak Cut bacon was awesome.&nbsp; See that jar there?&nbsp; Rick G. claims it&rsquo;s moonshine.&nbsp; I don&rsquo;t know how he got it.</p>
<p align="center">
	&nbsp;</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=6b5a258e-cda6-4a27-9c1b-03171c77f76a"><img alt="009" border="0" height="484" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=8e547902-a06a-44d1-8c73-72f26ca06720" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="009" width="644" /></a></p>
<p align="center">
	Yes, that&rsquo;s a donut.&nbsp; Yes, we eat dangerously.&nbsp; Just not every day.</p>
<p align="center">
	&nbsp;</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=09ab3b0a-4700-436c-9f9a-3af502bb5821"><img alt="011" border="0" height="484" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=e0ce4c90-5663-477b-b972-c4bbe61a7d5d" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="011" width="644" /></a></p>
<p align="center">
	Sadly, as delicious as it looks, it didn&rsquo;t taste that great &ndash; it tasted like a hot, extra greasy donut.</p>
<p align="center">
	&nbsp;</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=2194b2d3-3d2f-44d9-9877-f03ff1e25f09"><img alt="017" border="0" height="484" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=cd530618-bc40-4b8c-9352-4da06b065175" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="017" width="644" /></a></p>
<p align="center">
	Elaine and her animatronic hat.</p>
<p align="center">
	&nbsp;</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=71869dbd-c05a-43ca-ae71-a790e4b9274d"><img alt="025" border="0" height="484" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=6da32ead-e6d3-4079-bf2c-644511cbe9de" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="025" width="644" /></a></p>
<p align="center">
	Rick C. opening Docubot gifts.</p>
<p align="center">
	&nbsp;</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=dceda819-2028-4086-a113-caffd9e194bf"><img alt="030" border="0" height="484" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=4a6513ac-9a22-4ea7-bf35-6dfb2bc6621c" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="030" width="644" /></a></p>
<p align="center">
	Engineering Kevin preparing to shuffle.</p>
<p align="center">
	&nbsp;</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=43980a72-d7b0-48d0-8877-b5776585efdd"><img alt="015" border="0" height="484" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=8f371817-5042-4d8d-838e-e9d15bfeca2f" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="015" width="644" /></a></p>
<p align="center">
	Marco conferenced in.</p>
<p align="center">
	&nbsp;</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=733ef212-8148-406c-be50-b0b938c75087"><img alt="036" border="0" height="484" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=29394b15-c26c-4964-85c7-db93fedf1cb1" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="036" width="644" /></a></p>
<p align="center">
	Asia with morning coffee.</p>
<p align="center">
	&nbsp;</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=4c5f43b0-9976-4f3f-8175-3012434a4289"><img alt="032" border="0" height="484" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=0b9b6992-4910-4375-8e7e-c812a95fd796" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="032" width="644" /></a></p>
<p align="center">
	Lou recreated Eric&rsquo;s tragic dodge ball accident</p>
<p align="center">
	&nbsp;</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=8c318f27-1322-4fc8-b940-7e91d96d1053"><img alt="020" border="0" height="484" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=ca9bcc21-a4e7-4288-8f27-a098b3f48481" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="020" width="644" /></a></p>
<p align="center">
	Eric, clearly excited to open his Docubot gift.</p>
<p align="center">
	&nbsp;</p>
<p align="center">
	&nbsp;</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=f3ee94a8-30f6-4689-ae36-0784f2d83ecd"><img alt="007" border="0" height="218" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=f77526de-6171-4c97-b40a-385fbb14587c" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="007" width="644" /></a></p>
<p align="center">
	Yes. Yes you are.</p>
]]></description>
     <pubDate>Fri, 21 Dec 2012 12:24:04 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/december-2012/merry-christmas-and-happy-holidays-from-atalasoft]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/january-2013/what-does-it-take-to-be-a-software-developer]]></guid>
     <title><![CDATA[What Does It Take To Be A Software Developer?]]></title>
     <description><![CDATA[<p>
	I saw <a href="http://ask.metafilter.com/232409/Math-major-wants-to-be-a-software-developer">this question</a> on <a href="http://www.metafilter.com/">Metafilter</a> about what CS courses are necessary to be a software developer and thought I would take the opportunity to expound a bit.</p>
<p>
	The first non-useful answer is: all of it.&nbsp; I went to <a href="http://new.oberlin.edu/">Oberlin</a>, a college that only grants arts degrees, and received a degree in computer science.&nbsp; In that time, I also took classes in religion, ethnomusicology, physics, media, anthropology, and so on.&nbsp; Anything that seemed interesting and I could schedule, I tried to take. I honestly believe in the value of breadth in many things and depth in a few things.&nbsp; The value is especially apparent in software where solutions frequently need to be tailored to the problem domain and the possible number of domains that can be addressed effectively with software grows daily.&nbsp; If you know about a wide number of things, you can better tailor solutions to those domains.&nbsp; Being a lifelong learner makes it easier to learn new problem domains.</p>
<p>
	The second answer, more useful perhaps, is the following.</p>
<p>
	<strong>An intro class in a high-level language </strong>&ndash; you&rsquo;ll probably find classes taught in Java, C#, Python, Ruby, or C++.&nbsp; My first CS class in college was in Pascal.&nbsp; If you already know a HLL, it&rsquo;s still worthwhile, especially if it&rsquo;s a different language.&nbsp; In fact, you might want to look at the entire course book to see if all the classes are taught in only one or two languages.&nbsp; That&rsquo;s a bad sign, especially for a budding software developer where you should <em>expect</em> to need to learn a new language every few years.&nbsp; I know more than 20 and it is a career skill to pick up a new one in short order.</p>
<p>
	<strong>A class in algorithms and analysis</strong> &ndash; this is probably the one that I touch on the most without ever really having to crack a book (I do keep the textbook in my office in case), just for the ability to analyze the best, worst and average cases of code I write.&nbsp; I have encountered code in the wild that search for the first/next instance of a string in a stream that was O(<em>n!</em>) &ndash; easy to spot if you know what to look for.</p>
<p>
	<strong>A class in design patterns</strong> &ndash; I don&rsquo;t know if this is in any college curriculum, but when I started my professional career, there weren&rsquo;t any formal design patterns.&nbsp; They were informal and maybe differently named from shop-to-shop.&nbsp; I did discover that many of us had invented the same things just to get a job done and the wise ones abstracted them just enough to be able to apply them in many circumstances while keeping them nimble (for example, I had a tight library that was built around the <a href="http://en.wikipedia.org/wiki/Visitor_pattern">Visitor</a> pattern which was the basis for an entire UI toolkit.</p>
<p>
	<strong>A class in system architecture</strong> &ndash; in my day, this was called assembly, but I believe that a good solid understanding of the hardware underneath your computer is key to making good high level decisions as well as making you a far better debugger.&nbsp; It is also necessary for writing a compiler.</p>
<p>
	<strong>The Scheme/Functional class</strong> &ndash; if you&rsquo;re lucky, your department will have a Scheme zealot.&nbsp; I&rsquo;ll be honest, I hated Scheme.&nbsp; I&rsquo;m a very concrete/practical programmer by nature and Scheme drove me crazy.&nbsp; Not because I didn&rsquo;t understand it &ndash; I did.&nbsp; It drove me nuts how fluffy the language was in terms for how it worked and how code I wrote would stall for chunks of time while the garbage collector went to work to get rid of all the things I allocated that I couldn&rsquo;t prevent.&nbsp; I swear I was the worst offender of using set! and its variants in my code just to avoid wasting time/memory.&nbsp; Still, in spite of the structural language deficiencies, it is a fabulous language for getting you to stop thinking about problems sequentially.</p>
<p>
	<strong>A class in compilers</strong> &ndash; this was my hardest class, I think.&nbsp; I flunked it.&nbsp; But it was the most valuable class for learning how to debug a high level language from the lowest level.&nbsp; You should get to the point where you can look at machine generated assembly language and mentally decompile it into the HLL that made it.&nbsp; For example, I had a third party library that worked most of the time, but crashed at other times.&nbsp; It turns out that they were using C enums in size-dependent data structure and their compiler chose one size for the enum and my compiler chose a different size.&nbsp; Without being able to understand what a compiler would have done with code to operate on structs that contained this enum, I would&rsquo;ve been dead in the water.&nbsp; I run into this kind of thing All. The. Time.</p>
<p>
	<strong>A class in operating systems</strong> &ndash; and by extension, this class should cover concurrency and resource management.&nbsp; You&rsquo;re writing code and you&rsquo;re running it on what now?&nbsp; You should understand how an operating system works, how to write device drivers, and especially concurrency.&nbsp; When every machine, including your phone, is shipping with a couple cores, you should understand how to best leverage concurrent programming.</p>
<p>
	Beyond that, everything else is gravy.&nbsp; Also consider a writing class of some kind. Clear communication is vital and it <em>is</em> one of the things that I use to pick a new hire.</p>
]]></description>
     <pubDate>Mon, 07 Jan 2013 14:52:47 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/january-2013/what-does-it-take-to-be-a-software-developer]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/january-2013/how-to-manage-temporary-files]]></guid>
     <title><![CDATA[How to Manage Temporary Files]]></title>
     <description><![CDATA[<p>
	If you&rsquo;ve written software to manipulate large chunks of data, you&rsquo;ve likely created temporary files to hold the data for you. And if you&rsquo;re like me, your machine currently has 2587 files in your personal Temp folder. Why? Chances are there are a ton of apps on your system that are Doing It Wrong. I&rsquo;m going to talk about how most apps do this, how it goes horribly wrong, and what you can do to mitigate this problem for your own code.</p>
<p>
	Most apps will get the path to the Temp folder and run a loop creating files based on time stamp or time stamp followed by iteration until they succeed in making a new file. This path (or stream) gets used in the application in some manner and at some point in the future it will get removed. And you can bet that it&rsquo;s the last step where applications screw up &ndash; they don&rsquo;t (or can&rsquo;t) clean up after themselves.</p>
<p>
	If you&rsquo;re using Path.GetTempFileName(), stop. Seriously. Just stop using it. It&rsquo;s not appropriate. It tries to create a file in the form tmpXXXX.tmp, where XXXX is a 4 digit hex number. This is not appropriate for a couple reasons. First, in my own folder, there are currently 2516 files that match that pattern. In other words, 2516/65536 or 3.8% of the files are already in use and I swear I cleaned out that folder a couple months ago. In short order, it will fill up. Further, every nth call will take longer, as the first n-1 tries to make the file will fail. On top of that, there is no infrastructure to take care of the temporary file when you&rsquo;re done with it. The developer is responsible for removing it and we know how well developers remember to do things.</p>
<p>
	This is a resource problem: a limited number of slots and responsibility to get and release the resource is in the hands of the developer. When you approach this as a resource problem, it becomes a whole lot harder to screw up.</p>
<p>
	So let&rsquo;s set a few goals for this task. This code should be:</p>
<ul>
	<li>
		Easy to use</li>
	<li>
		Hard to screw up</li>
	<li>
		Customizable</li>
	<li>
		Better than Path.GetTemporaryFile()</li>
</ul>
<p>
	So let&rsquo;s start with a TemporaryFile object. This is what is going to hold your information about the temporary file. There are a number of ways this could be structured to be more flexible (like a template base class wherein subclasses could be any Stream instead of a FileStream), but it&rsquo;s called Temporary<strong>File</strong> not Temporary<strong>Stream</strong>, so let&rsquo;s keep it simple. Here is TemporaryFile:</p>
<pre>
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> TemporaryFile : IDisposable
</pre>
<pre class="code">
    {
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> TemporaryFile(<span style="color: #0000ff">string</span> path)
</pre>
<pre class="code">
        {
</pre>
<pre class="code">
            <span style="color: #0000ff">if</span> (path == <span style="color: #0000ff">null</span>)
</pre>
<pre class="code">
                <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentNullException(&quot;<span style="color: #8b0000">path</span>&quot;);
</pre>
<pre class="code">
            Path = path;
</pre>
<pre class="code">
            TemporaryStream = <span style="color: #0000ff">new</span> FileStream(path, FileMode.Create);
</pre>
<pre class="code">
        }
</pre>
<pre class="code">
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> Stream TemporaryStream { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">private</span> <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Path { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">private</span> <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">string</span> ToString()
</pre>
<pre class="code">
        {
</pre>
<pre class="code">
            <span style="color: #0000ff">return</span> Path;
</pre>
<pre class="code">
        }
</pre>
<pre class="code">
</pre>
<pre class="code">
        <span style="color: #0000ff">private</span> <span style="color: #0000ff">bool</span> _disposed = <span style="color: #0000ff">false</span>;
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Dispose()
</pre>
<pre class="code">
        {
</pre>
<pre class="code">
            Dispose(<span style="color: #0000ff">true</span>);
</pre>
<pre class="code">
            GC.SuppressFinalize(<span style="color: #0000ff">this</span>);
</pre>
<pre class="code">
        }
</pre>
<pre class="code">
</pre>
<pre class="code">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> Dispose(<span style="color: #0000ff">bool</span> disposing)
</pre>
<pre class="code">
        {
</pre>
<pre class="code">
            <span style="color: #0000ff">if</span> (!_disposed)
</pre>
<pre class="code">
            {
</pre>
<pre class="code">
                <span style="color: #0000ff">if</span> (disposing)
</pre>
<pre class="code">
                {
</pre>
<pre class="code">
                    TemporaryStream.Dispose();
</pre>
<pre class="code">
</pre>
<pre class="code">
                    File.Delete(Path);
</pre>
<pre class="code">
                }
</pre>
<pre class="code">
                _disposed = <span style="color: #0000ff">true</span>;
</pre>
<pre class="code">
            }
</pre>
<pre class="code">
        }
</pre>
<pre class="code">
</pre>
<pre class="code">
        ~TemporaryFile()
</pre>
<pre class="code">
        {
</pre>
<pre class="code">
            Dispose(<span style="color: #0000ff">false</span>);
</pre>
<pre class="code">
        }
</pre>
<pre class="code">
    }
</pre>
<pre class="code">
</pre>
<p>
	In this case, I chose to make the class itself immutable and Disposable. As it stands you could use this class as a wrapper around the result from Path.GetTemporaryFile(), but we&rsquo;ll do better than that. Remember that TemporaryFile is a <strong>resource</strong> and if that&rsquo;s the case, it should be IDisposable. We want to do something very specific when the file is closed.&nbsp; So following the pattern in <a href="http://atalasoft.com/cs/blogs/stevehawley/archive/2006/09/21/10887.aspx">IDisposable Made E-Z</a>, I&rsquo;ve made this class do a few things: open the file on construction and on disposal dispose the TemporaryStream and delete the path. According to <a href="http://msdn.microsoft.com/en-us/library/system.io.stream.close.aspx">the spec for Stream.Close()</a>, it is not necessary to call Close() but to instead ensure that Stream.Dispose() gets called. If either Stream.Dispose() or File.Delete() throw an exception, you probably have worse problems on your hands. If you wanted you could add an implementation of Equals and GetHashCode. I chose not to since pointer equality should be good enough.</p>
<p>
	Where possible, TemporaryFile objects should be scoped within a using() block to ensure they get disposed in a timely manner, otherwise you have to pray that the GC will help you out at the end of app life.</p>
<p>
	We&rsquo;re not done yet &ndash; as mentioned before, Path.GetTempFileName() gets worse the more you use it. We can fix that too. Also the filenames it generates are not so good in that we can&rsquo;t fingerprint them as our own so that we can check at a glance that we&rsquo;re leaking temp files or better yet, write a unit test to take care of them. So how do you make a TemporaryFile? Use a factory:</p>
<pre>
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> TemporaryFileFactory
</pre>
<pre class="code">
    {
</pre>
<pre class="code">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> kDefaultPrefix = &quot;<span style="color: #8b0000">Tmp</span>&quot;;
</pre>
<pre class="code">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> kDefaultSuffix = &quot;&quot;;
</pre>
<pre class="code">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> kDefaultExtension = &quot;<span style="color: #8b0000">tmp</span>&quot;;
</pre>
<pre class="code">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">int</span> kDefaultRetries = 10;
</pre>
<pre class="code">
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> TemporaryFile MakeTemporaryFile(<span style="color: #0000ff">string</span> extension) { <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> TemporaryFileFactory(<span style="color: #0000ff">null</span>, <span style="color: #0000ff">null</span>, <span style="color: #0000ff">null</span>, extension, kDefaultRetries).MakeTemporaryFile(); }
</pre>
<pre class="code">
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> TemporaryFileFactory(<span style="color: #0000ff">string</span> tempFolder, <span style="color: #0000ff">string</span> prefix, <span style="color: #0000ff">string</span> suffix, <span style="color: #0000ff">string</span> extension, <span style="color: #0000ff">int</span> retries)
</pre>
<pre class="code">
        {
</pre>
<pre class="code">
            <span style="color: #0000ff">if</span> (retries &lt;= 0) <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentOutOfRangeException(&quot;<span style="color: #8b0000">retries</span>&quot;);
</pre>
<pre class="code">
            Retries = retries;
</pre>
<pre class="code">
            TempFolder = String.IsNullOrEmpty(tempFolder) ? Path.GetTempPath() : tempFolder;
</pre>
<pre class="code">
            <span style="color: #0000ff">if</span> (!Directory.Exists(TempFolder))
</pre>
<pre class="code">
                <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> IOException(String.Format(&quot;<span style="color: #8b0000">Temporary folder &#39;{0}&#39; does not exist</span>&quot;, tempFolder));
</pre>
<pre class="code">
            Prefix = String.IsNullOrEmpty(prefix) ? kDefaultPrefix : prefix;
</pre>
<pre class="code">
            Suffix = suffix ?? kDefaultSuffix;
</pre>
<pre class="code">
            Extension = SanitizeExtension(extension ?? kDefaultExtension);
</pre>
<pre class="code">
        }
</pre>
<pre class="code">
</pre>
<pre class="code">
        <span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> SanitizeExtension(<span style="color: #0000ff">string</span> ext)
</pre>
<pre class="code">
        {
</pre>
<pre class="code">
            <span style="color: #0000ff">if</span> (ext.EndsWith(&quot;<span style="color: #8b0000">.</span>&quot;))
</pre>
<pre class="code">
                ext = ext.Substring(0, ext.Length - 1);
</pre>
<pre class="code">
            <span style="color: #0000ff">if</span> (ext.StartsWith(&quot;<span style="color: #8b0000">.</span>&quot;))
</pre>
<pre class="code">
                ext = ext.Substring(1);
</pre>
<pre class="code">
            <span style="color: #0000ff">if</span> (ext.Length == 0)
</pre>
<pre class="code">
                ext = kDefaultExtension;
</pre>
<pre class="code">
            <span style="color: #0000ff">return</span> ext;
</pre>
<pre class="code">
        }
</pre>
<pre class="code">
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> TempFolder { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">private</span> <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Prefix { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">private</span> <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Suffix { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">private</span> <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Extension { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">private</span> <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> Retries { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">private</span> <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
</pre>
<pre class="code">
        <span style="color: #0000ff">public</span> TemporaryFile MakeTemporaryFile()
</pre>
<pre class="code">
        {
</pre>
<pre class="code">
            <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; Retries; i++)
</pre>
<pre class="code">
            {
</pre>
<pre class="code">
                <span style="color: #0000ff">string</span> path = GenerateTemporaryPath(i);
</pre>
<pre class="code">
                <span style="color: #0000ff">if</span> (!File.Exists(path))
</pre>
<pre class="code">
                    <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> TemporaryFile(path);
</pre>
<pre class="code">
            }
</pre>
<pre class="code">
            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> IOException(String.Format(&quot;<span style="color: #8b0000">Unable to create temporary file in {0} after {1} {2}.</span>&quot;, TempFolder, Retries, (Retries == 1 ? &quot;<span style="color: #8b0000">try</span>&quot; : &quot;<span style="color: #8b0000">tries</span>&quot;)));
</pre>
<pre class="code">
        }
</pre>
<pre class="code">
</pre>
<pre class="code">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> kDefaultFormat = &quot;<span style="color: #8b0000">{0}{1}{2}.{3}</span>&quot;;
</pre>
<pre class="code">
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">string</span> GenerateTemporaryPath(<span style="color: #0000ff">int</span> retry)
</pre>
<pre class="code">
        {
</pre>
<pre class="code">
            Guid g = Guid.NewGuid();
</pre>
<pre class="code">
            <span style="color: #0000ff">string</span> newPath = Path.Combine(TempFolder, String.Format(kDefaultFormat, Prefix, g.ToString(&quot;<span style="color: #8b0000">N</span>&quot;), Suffix, Extension));
</pre>
<pre class="code">
            <span style="color: #0000ff">return</span> newPath;
</pre>
<pre class="code">
        }
</pre>
<pre class="code">
    }
</pre>
<pre class="code">
</pre>
<p>
	In this case, we&rsquo;re making the factory easy to use if you don&rsquo;t care about the file name format and easy to customize if you do. The first thing you should know is that I&rsquo;m defining the format of a temporary file name this way &ndash; &lt;Prefix&gt;&lt;content&gt;&lt;Suffix&gt;.&lt;Extension&gt;. The defaults are such that you should get Tmp&lt;content&gt;.tmp for your temporary file. There is a main constructor that takes values for Prefix and Suffix and Extension and defaults them if they are null (or in some cases null or empty). The constructor also takes a path to the folder you want to use for temporary files, but you can also set this to null and it will use Path.GetTempPath() instead. The question is, what should go in the &lt;content&gt; part of the file? Why not use a <a href="http://en.wikipedia.org/wiki/Globally_unique_identifier">GUID</a>? Just from the definition, I&rsquo;m fairly certain that I only have to check once to see if the path will exist since the GUID should be unique by definition. Still, GenerateTemporaryPath() was made virtual so you could override if this doesn&rsquo;t suit your particular needs. GenerateTemporaryPath() includes a retry number, so you could reimplement Path.GetTempFileName if you wanted to (but why?). There&rsquo;s some basic error checking/patching to mitigate pilot error in SanitizeExtension() and finally a nice static factory method that <a href="http://atalasoft.com/blogs/stevehawley/november-2012/jargon">news up</a> a factory for you with defaults and generates a TemporaryFile for you. Here&rsquo;s my test code:</p>
<pre>
</pre>
<pre class="code">
        <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args)
</pre>
<pre class="code">
        {
</pre>
<pre class="code">
            List&lt;<span style="color: #0000ff">string</span>&gt; files = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">string</span>&gt;();
</pre>
<pre class="code">
</pre>
<pre class="code">
            <span style="color: #0000ff">try</span>
</pre>
<pre class="code">
            {
</pre>
<pre class="code">
                <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; 20; i++)
</pre>
<pre class="code">
                {
</pre>
<pre class="code">
                    <span style="color: #0000ff">using</span> (TemporaryFile tf = TemporaryFileFactory.MakeTemporaryFile(<span style="color: #0000ff">null</span>))
</pre>
<pre class="code">
                    {
</pre>
<pre class="code">
                        files.Add(tf.Path);
</pre>
<pre class="code">
                        Console.WriteLine(&quot;<span style="color: #8b0000">Created </span>&quot; + tf.Path);
</pre>
<pre class="code">
                        <span style="color: #0000ff">if</span> (i &gt; 18)
</pre>
<pre class="code">
                            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> Exception(&quot;<span style="color: #8b0000">no purpose</span>&quot;);
</pre>
<pre class="code">
                    }
</pre>
<pre class="code">
                }
</pre>
<pre class="code">
            }
</pre>
<pre class="code">
            <span style="color: #0000ff">catch</span> { }
</pre>
<pre class="code">
            <span style="color: #0000ff">finally</span>
</pre>
<pre class="code">
            {
</pre>
<pre class="code">
                <span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> path <span style="color: #0000ff">in</span> files)
</pre>
<pre class="code">
                {
</pre>
<pre class="code">
                    <span style="color: #0000ff">if</span> (File.Exists(path))
</pre>
<pre class="code">
                        Console.WriteLine(&quot;<span style="color: #8b0000">error - file </span>&quot; + path + &quot;<span style="color: #8b0000"> still exist.</span>&quot;);
</pre>
<pre class="code">
                }
</pre>
<pre class="code">
            }
</pre>
<pre class="code">
        }
</pre>
<pre class="code">
</pre>
<p>
	which demonstrates how to make TemporaryFiles using the static factory method within a using and throws an exception for no other reason than to demonstrate the IDisposable does what it says on the box.</p>
<p>
	From an architecture point of view, this is good enough. It could be slightly cleaner and if I were to make any changes at all, I might put the static factory method(s) inside of TemporaryFile instead of TemporaryFileFactory, then I would call the methods Create(). If I wanted to hide the implementation details of TemporaryFile, I would probably make an interface ITemporaryStream and only put the TemporaryStream property in it. Then if you wanted to use a MemoryStream based factory you could. I think this is poor decision for a few reasons:</p>
<ul>
	<li>
		Temporary files are well established in the art</li>
	<li>
		MemoryStreams (or other streams) don&rsquo;t have the same need for a file deletion as a FileStream and fall outside of our problem domain</li>
	<li>
		It would necessitate either a factory for specific file streams</li>
	<li>
		Existing code isn&rsquo;t always .NET Stream compatible (for example, a C library that needs a path)</li>
</ul>
<p>
	So you see that by looking at the task as a resource problem rather than a temporary file problem, we can make a solution that is as easy to use and more resilient.</p>]]></description>
     <pubDate>Wed, 09 Jan 2013 14:09:30 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/january-2013/how-to-manage-temporary-files]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/january-2013/being-lazy-is-a-virtue]]></guid>
     <title><![CDATA[Being Lazy is a Virtue]]></title>
     <description><![CDATA[<p>
	One of the things that I admire in solid programmers is laziness.&nbsp; Some programmers will go to extreme lengths to avoid doing certain classes of work and frankly, I can&rsquo;t blame them really.&nbsp; For example, if you need to have a set of look up tables in code from some specification, you could just pull of the spec and start typing in the tables.&nbsp; A clever programmer will look at the task and start asking the following questions:</p>
<ol>
	<li>
		How much typing will each entry in the table take (and by extension, how long will the whole task take)?</li>
	<li>
		How many mistakes will I make just typing?</li>
	<li>
		How long will it take to find all of them?</li>
	<li>
		How long will it take to fix all of them?</li>
	<li>
		How irate will my customers get because of 3 and 4?</li>
</ol>
<p>
	When 1 gets measured in any units greater than &lsquo;minutes&rsquo; and 3 gets measured in units of days to years, a very clever programmer will also ask, &ldquo;how can I automate this?&rdquo;</p>
<p>
	This week I was looking at creating a number of tables (22 in all), each of which had somewhere around 200 entries in them.&nbsp; That&rsquo;s around 4000-4800 entries to type in.&nbsp; Yuck.&nbsp; That&rsquo;s easily 3 days of typing and the number of mistakes would probably be about 10%, which would easily be another day to catch 95% of those errors and weeks for the rest.</p>
<p>
	Enter the robot.</p>
<p>
	First trick, look at your source data and see if you can easily parse it.&nbsp; For example, I needed to parse Adobe Font Metrics files and <a href="http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/font/pdfs/5004.AFM_Spec.pdf">the spec is blissfully simple</a>.&nbsp; It&rsquo;s mostly a collection of one key/value pair per line as well as a set of separately subsection with differently formatted key/value pairs, several per line.&nbsp; In this case, I decided to put reflection to work for me, since all of the keys overlapped the set of names allowed in .NET object properties.&nbsp; On top of that, the tokenization can be done with String.Split().&nbsp; I&rsquo;m already on board.&nbsp; Here&rsquo;s the guts of the parsing code:</p>
<pre class="code">
</pre>
<pre class="code">
<span style="color: #0000ff">while</span> (<span style="color: #0000ff">true</span>)
</pre>
<pre class="code">
{
</pre>
<pre class="code">
    <span style="color: #0000ff">string</span> line = reader.ReadLine();
</pre>
<pre class="code">
    <span style="color: #0000ff">if</span> (line == <span style="color: #0000ff">null</span>)
</pre>
<pre class="code">
        <span style="color: #0000ff">break</span>;
</pre>
<pre class="code">
    <span style="color: #0000ff">string</span>[] pieces = line.Split(<span style="color: #0000ff">new</span> <span style="color: #0000ff">char</span>[] { &#39; &#39;, &#39;\t&#39; }, StringSplitOptions.RemoveEmptyEntries);
</pre>
<pre class="code">
    <span style="color: #0000ff">if</span> (pieces.Length == 0)
</pre>
<pre class="code">
        <span style="color: #0000ff">continue</span>;
</pre>
<pre class="code">
    <span style="color: #0000ff">string</span> delimeter = pieces[0];
</pre>
<pre class="code">
    <span style="color: #0000ff">switch</span> (delimeter)
</pre>
<pre class="code">
    {
</pre>
<pre class="code">
        <span style="color: #0000ff">case</span> &quot;<span style="color: #8b0000">StartCharMetrics</span>&quot;:
</pre>
<pre class="code">
            ParseCharMetrics(metrics, reader, GetInteger(pieces[1]));
</pre>
<pre class="code">
            <span style="color: #0000ff">break</span>;
</pre>
<pre class="code">
        <span style="color: #0000ff">default</span>:
</pre>
<pre class="code">
            SetProperty(metrics, delimeter, pieces);
</pre>
<pre class="code">
            <span style="color: #0000ff">break</span>;
</pre>
<pre class="code">
    }
</pre>
<pre class="code">
    <span style="color: #0000ff">if</span> (line == <span style="color: #0000ff">null</span>)
</pre>
<pre class="code">
        <span style="color: #0000ff">break</span>;
</pre>
<pre class="code">
}
</pre>
<pre class="code">
</pre>
<p>
	SetProperty is very simple &ndash; it just looks for a property named by delimeter with a setter and when it finds it type coerces the string value to the property type and sets it.&nbsp; Most of the conversion is done with System.Convert, which is easy.</p>
<p>
	For the main AFM file, I project the data onto an object that looks like this:</p>
<pre class="code">
</pre>
<pre class="code">
<span style="color: #0000ff">class</span> GlobalFontMetrics
</pre>
<pre class="code">
{
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FontName { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FullName { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FamilyName { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Weight { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span>[] FontBBox { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Version { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Notice { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> EncodingScheme { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> MappingScheme { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> EscChar { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> CharacterSet { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> Characters { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> IsBaseFont { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span>[] VVector { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> IsFixedV { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> CapHeight { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> Ascender { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> Descender { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> StdHW { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> StdVW { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> XHeight { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
</pre>
<pre class="code">
}
</pre>
<p>
	Now, all of this code is scaffolded into my unit tests and the output of each test is one or more .cs file containing code that constructs the tables from the AFM data. These source files are then added into the main project &ndash; but not automatically.</p>
<p>
	Now, suppose that you have source data that isn&rsquo;t quite so easy to parse as AFM files.&nbsp; In my case I needed to build encoding tables for the various supported standard encodings in PDF, including StandardEncoding, MacRomanEncoding, and WinAnsiEncoding.&nbsp; These are listed out in the spec as tables.&nbsp; Fortunately, I could copy them within Acrobat and then paste them into Excel.&nbsp; From Excel, I ran a set of functions that transformed the data into abbreviated lists that I could use and then was able to turn that into C# with a handful of regular expressions.&nbsp; This is not as ideal as the tables are not as easily reproducible, but hopefully this won&rsquo;t have to be done again.</p>
<p>
	All in all, the code and Excel chicanery took me two days to implement, verify, and unit test, far less than just typing in the tables and I&rsquo;m far more confident that the data is correct.</p>
]]></description>
     <pubDate>Wed, 30 Jan 2013 13:18:03 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/january-2013/being-lazy-is-a-virtue]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/february-2013/failure-modes]]></guid>
     <title><![CDATA[Failure Modes]]></title>
     <description><![CDATA[<p>
	Software engineering is funny.&nbsp; It shares a lot with Computer Science (which honestly, should be called applied mathematics) and it shares some things with other engineering disciplines.&nbsp; With other engineering disciplines, it shares the need for clear processes for planning projects, managing work, ensuring quality, and handling defects.&nbsp; I say that it shares the <em>need</em> because not every shop actually does all of these things and there is certainly no one good standard for any of these.&nbsp; This is an industry problem.</p>
<p>
	One of the many nice things about being married to a real engineer is that I get to hear a lot about engineering and manufacturing process and one of the things I&rsquo;ve heard her (and other engineers) talk about is <a href="http://en.wikipedia.org/wiki/Failure_mode_and_effects_analysis">FMEA</a>: Failure Mode and Effects Analysis.&nbsp; This is process whereby a component can be analyzed for failure and severity or probability of failure can be reduced or eliminated.&nbsp; This is what I thought of when one of my LCD monitors failed.</p>
<p>
	We believe that engineers work better when there is more screen real estate available to them.&nbsp; We also believe that an investment in a good pair of monitors will pay off in terms of other resources saved.&nbsp; For example, our office supply sales representative asked us in all honesty if we were buying our paper from another source, since we go through very little paper (but a great deal of coffee).&nbsp; We purchased a fair number of these LCD monitors from a well-known consumer electronics manufacturer.&nbsp; In a few years, they started failing.&nbsp; In the past 6 months we have had 4 fail.&nbsp; Every single monitor failed in exactly the same way: the display went blank and the power light went off.&nbsp; After a brief pause, the monitor started back up again.&nbsp; The frequency of failures increase until the monitor fails to work at all.&nbsp; This to me screams of being a very analog problem, probably power related.&nbsp; To date, 68% of our monitors failed this way.</p>
<p>
	I contacted the manufacturer of these monitors to find out if there are replacement parts available, hoping that they would have an FMEA put together with this device that would pick out the likely culprit.&nbsp; I received worse than no help from the manufacturer, but <a href="http://atalasoft.com/blogs/support">Elaine</a> will talk in more detail from a support point of view about what they did wrong and how they could&rsquo;ve done it right.</p>
<p>
	Since I&rsquo;m alone in this I chose to ignore the manufacturer&#39;s lawyers.&nbsp;</p>
<p>
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=8c89f300-5f6a-4103-8921-20dce85ac737"><img alt="image" border="0" height="50" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=c4e21d01-fa35-4ee3-8c31-7ec79116f69d" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="image" width="504" /></a></p>
<p>
	By the way &ndash; unlike this manufacturer, I&rsquo;m going to say that if you&rsquo;re deciding to do this, you should understand the risks. Power supplies in electronic devices can have components that will hold onto a charge long after they&rsquo;ve been shut off. If you&rsquo;re uncomfortable doing something like rewiring parts of your house, listen to your discomfort and don&rsquo;t do this since the charge in a typical power supply cap can give you a nice burn or stop your heart. You know, bad things if you&rsquo;re not appropriately careful.</p>
<p>
	I took the monitor apart and looked over the various boards to see if anything obvious was out of kilter and here&rsquo;s what I found:</p>
<p>
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=66a28144-53ad-4b87-8e1e-1439de4f7ee6"><img alt="image" border="0" height="540" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=060f2f13-d77b-440c-b40b-a39a6cc370c0" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="image" width="504" /></a></p>
<p>
	There are three of these capacitors on the board used to drive the <a href="http://en.wikipedia.org/wiki/Cold_cathode">CCFL</a> that is used as a backlight to the LCD display.&nbsp; If you look at the top of the cap, you can see it bulging up.&nbsp; <a href="http://en.wikipedia.org/wiki/Capacitor_plague">This is a sign that this part is failing or has failed</a>.&nbsp; The manufacturer either used the cheapest caps they could find or used underrated parts or both (or heck, even something else).&nbsp; The point is that all three of the capacitors on this board look like this, and I would expect a large consumer electronics manufacturer to know about this, to admit to it, and to have a well-defined process for managing it, as well as to have fixed the problem in later revisions (and I can tell you that the manufacturing dates indicate on our devices that they likely did nothing of the sort).</p>
<p>
	Unfortunately, this part isn&rsquo;t well-marked so I can&rsquo;t tell you what the capacitance or the rating are, but taking a guess, this particular part probably cost them a few cents in quantity, whereas a higher quality part would have cost roughly 10 cents in quantity.&nbsp; So someone looked at the design and chose an off-brand manufacturer for the part in order to save 25 cents on the assembly.</p>
<p>
	The actual cost of this problem was probably far higher in terms of in-warrantee repairs.&nbsp; Sadly, the most costly loss to this manufacturer is in terms of customer loyalty.&nbsp; I had a CRT from the same manufacturer that I used for 10 years before replacing it with a smaller footprint, less power-hungry LCD.&nbsp; That CRT looked every bit as good on the last day as it did on the first day.&nbsp; The shoddy quality of these LCD devices and the especially poor customer service is such that<strong> I will never purchase another product from this manufacturer again</strong> and if I have a say in the matter, I will strongly discourage anyone I know or work for from purchasing their products.</p>
<p>
	By comparison, I have a workstation made by another well-known consumer electronics manufacturer on my desk which I use for my day-to-day work.&nbsp; The computer shut down without warning.&nbsp; We reported this to the manufacturer and even though it was out of warrantee, they sent us a replacement motherboard and power supply which arrived the very next day.&nbsp; When we replaced the board, we noted that the bad motherboard had several capacitors that were bulged up.&nbsp; The replacement motherboard had caps made by a different manufacturer.</p>
<p>
	And while a desktop workstation is a different beast than a monitor, the desktop manufacturer demonstrated that the proper way to handle this type of problem is with alacrity not with incompetence.</p>
]]></description>
     <pubDate>Tue, 19 Feb 2013 14:41:27 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/february-2013/failure-modes]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/may-2013/why-typography-matters]]></guid>
     <title><![CDATA[Tying Things Together: Why Typography Matters]]></title>
     <description><![CDATA[<p>
	Quick &ndash; take a look at this excerpt from a Dr. Seuss book:<br />
	<br />
	<br />
	<br />
	<br />
	<br />
	<br />
	<br />
<br />
<br />
	&nbsp;</p>
<p>
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=bec2b1c1-c961-4653-ac62-ce7710634b60"><img alt="ligatures" border="0" height="155" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=5d1d5c33-4a15-4732-9c02-771db8047491" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="ligatures" width="604" /></a></p>
<p>
	&nbsp;</p>
<p>
	I took this picture with my phone shortly after reading with my son and found this page particularly jarring.&nbsp; Like many technologies, automated type came from a hand-driven process.&nbsp; Writing used to be hand done until <a href="http://en.wikipedia.org/wiki/Johannes_Gutenberg">Gutenberg</a> and then after, it&rsquo;s been a continual struggle to get technology to be able to create something that can be done by a talented calligrapher.&nbsp; In this case, the problem is ligatures.&nbsp; Ligatures are sets of glyphs that are tied together (ligated) by their shapes.&nbsp; They are necessary because they improve the appearance and readability of a document.&nbsp; <a href="http://www.nikibrown.com/designoblog/2009/02/23/lovely-lovely-ligatures/">Here is a pretty good blog entry</a> on ligatures.</p>
<p>
	Now look back at the Seuss.&nbsp; Here&rsquo;s what I saw immediately (and I am not a typographer):</p>
<p align="center">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=6bbc6557-ba76-493d-b698-a006a4125259"><img alt="ffi" border="0" height="187" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=b34a2381-c1e5-4d2d-8567-43e6025c2dba" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="ffi" width="154" /></a><a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=4a7d398a-64a0-44c8-9b4e-0bebd6099f02"><img alt="fl" border="0" height="176" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=38a41b45-18c3-4f11-8e6e-fc8a3689edaf" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="fl" width="118" /></a><a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=1be5713b-485d-48ed-a7dc-c401040206f5"><img alt="ff" border="0" height="191" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=4591f804-4ea5-4bfa-9577-9dd93a58c7a1" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="ff" width="136" /></a></p>
<p>
	which are all pairs which should be replaced with an equivalent ligature.&nbsp; In particular, the fl is bad because of the f just barely touching the l and in the ffi, the dot from the i is almost but not quite hitting the second f.&nbsp; It feels off to me.</p>
<p>
	I first encountered ligatures while I was working on Adobe Acrobat version 1.0.&nbsp; I was assigned the task of &ldquo;fixing&rdquo; the built-in find tool, which as it stood could find a single word in the document and no more.&nbsp; I built it up to handle phrases and text that was perhaps on a curve (which made maps searchable).&nbsp; Working on this tool taught me about ligatures because, for example, that ffi in the document was represented by a single character which may or may not bear any relation to the actual glyph.&nbsp; So the text consuming code had to internally undo the text encoding and then undo the ligature expanding it to something that could be matched, but it had to keep the mapping so that we understood that three characters in the search key might not map to three glyphs on the page for highlighting.&nbsp; It was interesting and as a result my eye has been trained to spot ligatures, or more precisely to spot when ligatures are not there.</p>
<p>
	Here is what the above text looks like with ligatures in place &ndash; I approximated the font.&nbsp; It&rsquo;s not quite right, but it&rsquo;s close enough so you can see the difference</p>
<p>
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=fb0a5d19-2a21-4a3e-b885-5275fe570008"><img alt="ligatures" border="0" height="155" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=7f6e47d0-a4d8-4059-a8a2-7edf8122e545" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="ligatures" width="604" /></a></p>
<p>
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=f6935fe1-37bb-406a-9c04-db6a8a17cc26"><img alt="ligatureswith" border="0" height="155" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=9a333974-2a67-456a-84b4-3dd2f3039c41" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="ligatureswith" width="604" /></a></p>
<p>
	&nbsp;</p>
<p>
	And to its credit, Photoshop did the ligatures for me as I typed in the text.&nbsp; I&rsquo;m glad that another engineer has had an eye for this detail. I can&rsquo;t wait for this to be better supported on the web.&nbsp; Chrome, Firefox and Safari appear to have support for it on Windows, but not Internet Explorer.</p>
]]></description>
     <pubDate>Fri, 10 May 2013 11:26:31 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/may-2013/why-typography-matters]]></link>
    
</item>
<item>
     <guid isPermaLink="true"><![CDATA[http://www.atalasoft.com/blogs/stevehawley/may-2013/how-to-split-a-cubic-bezier-curve]]></guid>
     <title><![CDATA[How to Split a Cubic Bézier Curve]]></title>
     <description><![CDATA[<p>
	Today I&rsquo;m going to get all mathy on you.&nbsp; Don&rsquo;t worry about it &ndash; it&rsquo;s going to be pretty simple math and in the end we&rsquo;re going to learn how to split a cubic Bézier curve into two new curves.</p>
<p>
	First, let&rsquo;s start off with parametric equations.&nbsp; This is a type of equation that adds a new variable, <em>t</em>, which can be thought of as time.&nbsp; In our world, <em>t</em> is going to range from 0 (the start) to 1.0 (the end).&nbsp; So for example, if I have a line segment from point A to point B, then point A is at time 0, point B is at time 1 and the midpoint is at time 0.5.</p>
<p>
	Let&rsquo;s look at midpoint briefly &ndash; you probably learned midpoint as this:</p>
<p align="center">
	<em>x&rsquo; = </em>(<em>x</em><sub>1</sub><em>&nbsp;</em>+<em> x</em><sub>0</sub>)/2</p>
<p align="center">
	<em>y&rsquo; = </em>(<em>y</em><sub>1</sub><em>&nbsp;</em>+<em> y</em><sub>0</sub>)/2</p>
<p>
	or simply, the average of the x&rsquo;s and the y&rsquo;s.&nbsp; But let&rsquo;s have some fun with this.&nbsp; I&rsquo;m going to only work with <em>x</em> components, but I assure you that this works just fine with both.&nbsp; First, I&rsquo;m going to rewrite that divide by 2 as a multiply by 0.5:</p>
<p align="center">
	<em>x&rsquo; = </em>(<em>x</em><sub>1</sub><em> </em>+<em> x</em><sub>0</sub>) * 0.5</p>
<p align="left">
	Now, let&rsquo;s distribute this over the terms:</p>
<p align="center">
	<em>x&rsquo; = </em>0.5<em>x</em><sub>1</sub><em> </em>+<em> </em>0.5<em>x</em><sub>0</sub></p>
<p align="left">
	Now, I&rsquo;m going to rewrite the second term as an equivalent:</p>
<p align="center">
	<em>x&rsquo; = </em>0.5<em>x</em><sub>1</sub><em> </em>+<em> -</em>0.5<em>x</em><sub>0</sub> + <em>x</em><sub>0</sub></p>
<p align="left">
	We simplify and associate:</p>
<p align="center">
	<em>x&rsquo; = </em>(<em>x</em><sub>1</sub><em> &ndash; </em><em>x</em><sub>0</sub>)<em> * </em>0.5 + <em>x</em><sub>0</sub></p>
<p align="left">
	This is an equivalent, if slightly more general version of midpoint.&nbsp; So why did we do that?&nbsp; Because we can now replace that 0.5 with <em>t</em> as time and we have a complete parametric equation for a line:</p>
<p align="center">
	<em>x&rsquo; = </em>(<em>x</em><sub>1</sub><em> &ndash; </em><em>x</em><sub>0</sub>)<em> * t</em> + <em>x</em><sub>0</sub></p>
<p align="center">
	<em>y&rsquo; = </em>(<em>x</em><sub>1</sub><em> &ndash; </em><em>y</em><sub>0</sub>)<em> * t</em> + <em>y</em><sub>0</sub></p>
<p align="left">
	I&rsquo;ve also given you the formula for linear interpolation from one point to another &ndash; it&rsquo;s the same.&nbsp; And to help you along, I&rsquo;m going to give you a new verb, lerp, which means to linear interpolate from A to B.</p>
<p align="left">
	Now, onto cubic Bézier curves.&nbsp; Here is a simple cubic Bézier curve which is defined by 4 points &ndash; two end points and two control points<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=da27a266-3f87-4015-bef7-02eaa375134e"><img alt="bezier1" border="0" height="313" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=6b96a1fd-9c48-4e23-bd23-8ad446967b46" style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="bezier1" width="337" /></a></p>
<p align="left">
	P0 and P3 are end points and P1 and P2 are the control points.&nbsp; The parametric formula for this curve is this:</p>
<p align="center">
	<em>x</em> = <em>a<sub>x</sub>t</em><sup>3</sup> + <em>b<sub>x</sub>t</em><sup>2</sup> +<em> c<sub>x</sub>t</em> + <em>x</em><sub>0</sub></p>
<p align="center">
	<em>y</em> = <em>a<sub>y</sub>t</em><sup>3</sup> + <em>b<sub>y</sub>t</em><sup>2</sup> +<em> c<sub>y</sub>t</em> + <em>y</em><sub>0</sub></p>
<p align="left">
	&nbsp;</p>
<p align="left">
	It looks like a handful, but it&rsquo;s not really that bad &ndash; it&rsquo;s a third degree polynomial that is a function of <em>t</em> and <strong>not</strong> of x or y.&nbsp; One tricky part is understanding the relationship between the four control points and the coefficients of the <em>t</em> terms.&nbsp; Again, let&rsquo;s work with just the <em>x</em> side, since the <em>y </em>equation will work out the same.&nbsp; I&rsquo;m not going to derive these for you &ndash; trust me.</p>
<p align="center">
	<em>a<sub>x</sub></em> = <em>x</em>3 &ndash; ( 3 * <em>x</em>2) + (3 * <em>x</em>1) &ndash; <em>x</em>0</p>
<p align="center">
	<em>b<sub>x</sub></em> = (3 * <em>x</em>2) &ndash; (6 * <em>x</em>1) + (3 * <em>x</em>0)</p>
<p align="center">
	<em>c<sub>x</sub></em> = (3 * <em>x</em>1) &ndash; (3 * <em>x</em>0);</p>
<p align="left">
	&nbsp;</p>
<p align="left">
	The variables <em>x</em>0 through <em>x</em>3 correspond to the X coordinates for points P0 through P3 in the diagram above.&nbsp; So let&rsquo;s look at splitting this Bézier in half.&nbsp; We&rsquo;ll do this graphically by first drawing in some guides:</p>
<p align="left">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=a983b653-fce1-4902-9a06-559502446714"><img alt="bezier2" border="0" height="313" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=9626012d-eee1-48f4-960f-c2e0c7a28223" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="bezier2" width="337" /></a></p>
<p align="left">
	I&rsquo;ve added a line between P1 and P2 and added three new points, P4, P5, and P6.&nbsp; Each of these points are at the midpoint of the segment on which they lie.&nbsp; Now, let&#39;s connect the midpoints together:</p>
<p align="left">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=c6e19b32-1ad9-4ccd-a26f-f278609946e7"><img alt="bezier3" border="0" height="313" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=bd120409-718d-4d50-be84-c97cb44f2baa" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="bezier3" width="337" /></a></p>
<p align="left">
	Here I&rsquo;ve added two new midpoints, P7 and P8.&nbsp; Repeat again to leave us with a new line and midpoint:</p>
<p align="left">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=35bbc093-6df0-4cf0-8e04-50d109bb85f8"><img alt="bezier4" border="0" height="313" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=9e4a76f4-36d2-41e7-8cb5-8501582eefd3" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="bezier4" width="337" /></a></p>
<p align="left">
	And P9 is on the right on the curve.&nbsp; Furthermore, the first section of the split curve from P0 to P9 can be described with the four points, P0, P4, P7 and P9:</p>
<p align="left">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=91fac116-cb3f-4daf-ba79-889d4fc6d91d"><img alt="bezier5" border="0" height="313" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=94509e76-5f2e-4a26-bed2-0e64eb715036" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="bezier5" width="337" /></a></p>
<p align="left">
	and the second part of the split curve and be described with points P9, P8, P6 and P3:</p>
<p align="left">
	<a href="http://atalasoft.com/CMSPages/GetFile.aspx?guid=2a964ab2-4a01-43a8-ab8e-5e90352afdf6"><img alt="bezier6" border="0" height="313" src="http://atalasoft.com/CMSPages/GetFile.aspx?guid=1e684987-ab05-4ca5-a47f-f2b00827c6d5" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="bezier6" width="337" /></a></p>
<p align="left">
	If you&rsquo;re still with me, you&rsquo;ll note that if you keep splitting the subcurves, you will eventually draw every point on the original curve.&nbsp; And you can do this all with calling midpoint successively.&nbsp; Generally speaking, in software we like this because midpoint is one add and one divide by two.&nbsp; If you&rsquo;re working in fixed point, this is wonderful because that becomes an add and a bitshift, both very fast instructions.&nbsp; In theory, I could do the subdivision of a curve in 14 instructions (plus about 7 instructions of overhead) per coordinate.&nbsp; That&rsquo;s really not a lot.&nbsp; There&rsquo;s a problem though &ndash; splitting a Bezier this way to, say, draw it with a series of straight lines is not so good as it&rsquo;s not obvious when you should subdivide further or be satisfied with what you have.&nbsp; In other words, a small change in <em>t</em> may make a substantial change in the distance traveled along the curve and the next change in <em>t</em> is likely NOT going to end up with the same change on the curve.&nbsp; So midpoint is not really the best way to do this.&nbsp; What if we wanted to use any arbitrary <em>t</em>?&nbsp; We could use the general formula above, but that may not be the best choice &ndash; we don&rsquo;t like the cubes and squares so much and while that will give as a point on the curve, it won&rsquo;t let us actually split the curve because we would be missing the new control points.</p>
<p align="left">
	So let&rsquo;s go back to our original midpoint formula and throw it away.&nbsp; Instead of using midpoint, we&rsquo;re going to use the parametric equivalent.&nbsp; So give the T you want, you get P4 by lerping from P0 to P1, you get P5 by lerping from P1 to P2, you get P6 by lerping from P2 to P3.&nbsp; Moving to the next step (red), you get P7 by lerping from P4 to P5, you get P8 by lerping from P5 to P6.&nbsp; Finally, to get P9 by lerping from P7 to P8.&nbsp; In implementation, each lerp is a multiply and two adds.&nbsp; 6 lerps is therefore 6 multiplies and 12 adds, or about 30 instructions.</p>
<p align="left">
	Now if we used the polynomial form each coordinate would be 5 multiplies and 3 adds per coordinate, but we wouldn&rsquo;t have the control points of the new curves and getting them turns out to be more work than just doing all the lerping in the other solution.</p>
<p align="left">
	There are two closely related problems that fall out from this work &ndash;<br />
	<br />
	1. How do I draw a cubic Bézier with the fewest/optimal straight line segments?<br />
	2. What is the length of a cubic Bézier curve?&nbsp;<br />
	<br />
	If you can solve the first problem, you can come up with an approximation for the second.&nbsp; We&rsquo;ll save this for another time, though.</p>
]]></description>
     <pubDate>Fri, 24 May 2013 11:47:08 GMT</pubDate>
     <link><![CDATA[http://www.atalasoft.com/blogs/stevehawley/may-2013/how-to-split-a-cubic-bezier-curve]]></link>
    
</item></channel>
</rss>
