Divelements Community
Customer discussion of all Divelements products

Outlook 2007-style text

Latest post 04-21-2007 12:52 by Tim Dawson. 5 replies.
  • 04-06-2007 9:31

    • Elkay
    • Top 10 Contributor
    • Joined on 08-15-2005
    • Posts 43

    Outlook 2007-style text

    I've been working with divelements controls for several years now - and writing my own custom render classes to suit my specific needs.

    Anyway, I thought I'd make a quick post here to show those of you who do like myself - how to create anti-aliased text for your applications.

    I do NOT own EyeFinder 1.3 or higher so the routine *might* be called something different now but I highly doubt it. Nevertheless, it'll be up to you 1.3+ owners to check first.

    Here's the old-school way of displaying text:

    Public Overrides Sub DrawHeader(ByVal graphics As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal text As String, ByVal font As System.Drawing.Font, ByVal image As System.Drawing.Image, ByVal rtl As Boolean)

    dim FontBrush as New SolidBrush(color.black)
    Dim TextFormat As New StringFormat
    TextFormat.FormatFlags = StringFormatFlags.NoWrap
    TextFormat.Trimming = StringTrimming.EllipsisCharacter
    TextFormat.Alignment = StringAlignment.Center
    TextFormat.LineAlignment = StringAlignment.Center

    graphics.DrawString(text, font, FontBrush, bounds, TextFormat)

    *************
    The above code will do exactly like you expect: Draws a string using the color described in FontBrush...

    But what if you want anti-aliased fonts like those found in Outlook 07 ?

    Well - it's really not much different!
    Instead of using the GDI method, Drawstring...instead use FillPath - of course you'll have to build your path but fortunately, paths are already setup to accept text:

    Dim TextGraphicsPath As New GraphicsPath
    TextGraphicsPath.AddString(pane.Text, font.FontFamily, font.Style, font.Size + 3, bounds, TextFormat)
    graphics.SmoothingMode = SmoothingMode.AntiAlias
    graphics.FillPath(FontBrush, TextGraphicsPath)

    * Note *
    See the +3 I threw onto the font.size parameter? That's because drawing text like this will make it smaller than you expected...I have no clue why and it's 3:30am here so I'm too tired to care at this time! If one of you excellent coders reading this happens to know why - please post a reply to let me and everyone else know!

    Enjoy :)

    -Elkay
  • 04-07-2007 7:42 In reply to

    Re: Outlook 2007-style text

    I'm absolutely not familiar with this at all, but just a wild guess... this method might be using Pixel instead of Point as the graphical unit to create the font it uses.

  • 04-08-2007 6:40 In reply to

    • Elkay
    • Top 10 Contributor
    • Joined on 08-15-2005
    • Posts 43

    Re: Outlook 2007-style text

    Yeah - I dug into it today and it was painfully obvious almost immediately.

    Fonts are displayed in Points which is an approximation of Dots per Inch (DPI)

    Its interesting to note that computers like to use the Printers standard, 72 dpi which is evenly divisible by 2, 3, 4, 6, 8, 9, 12...all of which are 'standard' font sizes.

    If you really want to get technical, it's not truely 72 dpi but a close approximation to it...which is why '8 point' is actually 8.25, etc. etc.

    ANYWAY - if you want to convert from Fon.Size to Pixels, you have to know your screen resolution - then you have to calculate the number of pixels per inch based on that resolution - now you can calculate the translation by (Font.Size / 72) * PixelsPerInch and there you have it.

    Wow...anyone else gotta take a nap after all that?

    I think I'll stick to adding +3 to my Font.Size and just be done with it.

    -Elkay
  • 04-20-2007 13:30 In reply to

    Re: Outlook 2007-style text

    It strikes me that it would be better to simply set the TextRenderingHint to force it to be rendered with ClearType - this is almost certainly how Outlook does it.

    In your DrawHeader implementation just set

    context.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

    And then restore to whatever it was previously after drawing your text. You should be drawing text with IndependentText.DrawText.
  • 04-21-2007 3:12 In reply to

    • Elkay
    • Top 10 Contributor
    • Joined on 08-15-2005
    • Posts 43

    Re: Outlook 2007-style text

    Your suggests worked fantastic Tim but you lost me with IndependentText.DrawText. I'm no GDI expert but dont recognize that function - or is it part of EyeFinder?

    -LK
  • 04-21-2007 12:52 In reply to

    Re: Outlook 2007-style text

    It's part of Eyefinder. It draws text using GDI or GDI+, depending on what is appropriate at the time. Eyefinder uses it exclusively internally.
Page 1 of 1 (6 items) | RSS
Copyright © 2008 Divelements Limited
Powered by Community Server (Commercial Edition), by Telligent Systems