title: PdfSharp: Text height/positioning problem
body: <p>Whether I use XTextFormatter or not, I get the same error about the LayoutRectangle having to have a height of 0 or something like this.</p>
  
  <pre><code>new PdfSharp.Drawing.Layout.XTextFormatter(_gfx).DrawString(text 
      , new PdfSharp.Drawing.XFont(fontName, fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle) 
      , new PdfSharp.Drawing.XSolidBrush(PdfSharp.Drawing.XColor.FromArgb(foreColour)) 
      , new PdfSharp.Drawing.XRect(new PdfSharp.Drawing.XPoint(xPos, yPos), new PdfSharp.Drawing.XPoint(xLimit, yLimit)) 
      , PdfSharp.Drawing.XStringFormats.Default);
  </code></pre>
  
  <p><strong>fontStyle</strong> is of type System.Drawing.FontStyle
  <strong>foreColour</strong> is of type System.Drawing.Color
  I have already predefined <strong>_gfx</strong> from a <strong>PdfPage</strong> with <em>Orientation = Landscape, Size = Letter</em>
  <strong>xPos</strong> and <strong>yPos</strong> are parameters of type double, the same with <strong>xLimit</strong> and <strong>yLimit</strong>.</p>
  
  <hr>
  
  <blockquote>
    <p>I get the runtime error that the
    LayoutRectangle must have a height of
    zero (0)...</p>
  </blockquote>
  
  <hr>
  
  <p>Per definition a rectangle is meant to have a height, otherwise call it a line! I don't get it!... </p>
  
  <p>I tried with the <strong>XGraphics.DrawString()</strong> method directly, and I get the same error. It seems that I can't use the LayoutRectangle but have to manage that the text fit within the desired area manually.</p>
  
  <pre><code>var textFont = new PdfSharp.Drawing.XFont(fontName, fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
  
  while (xPos + _gfx.MeasureString(text, textFont).Width &gt; xLimit)
      textFont = new PdfSharp.Drawing.XFont(fontName, --fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
  
  while (yPos + _gfx.MeasureString(text, textFont).Height &gt; yLimit &amp;&amp; fontSize &gt; 0)
      textFont = new PdfSharp.Drawing.XFont(fontName, --fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
  
  _gfx.DrawString(text
      , textFont
      , new PdfSharp.Drawing.XSolidBrush(PdfSharp.Drawing.XColor.FromArgb(foreColour))
      , new PdfSharp.Drawing.XPoint(xPos, yPos));
  </code></pre>
  
  <p>Though the yPos variable value is the exact same value!</p>
  
  <p><strong>*yPos = Page.Height * .4093, either 40,93% of the page's height.*</strong></p>
  
  <p>Herewith an example of what I try to do:</p>
  
  <blockquote>
    <p>"Hello World!"             "Hello
    World!"</p>
  </blockquote>
  
  <p>And here is what I get:</p>
  
  <blockquote>
  <pre><code>                      "Hello World!" 
  </code></pre>
    
    <p>"Hello World!"</p>
  </blockquote>
  
  <p>And because of different printing area limits and size of the font and the different font style, I can't just write these into one simple sentence including the correct number of spaces.</p>