Results 1 to 8 of 8

Thread: [RESOLVED] Graphics.RotateTransform for vertical aligned Text

  1. #1

    Thread Starter
    Hyperactive Member nickwrs's Avatar
    Join Date
    Jan 2000
    Location
    Atlanta, Ga
    Posts
    398

    Resolved [RESOLVED] Graphics.RotateTransform for vertical aligned Text

    Hi All,
    I'm using the following calls in a vertical label control: (borrowed from another project)

    Code:
    vlblControlWidth = this.Size.Width
    lblControlHeight = this.Size.Height
    e.Graphics.DrawRectangle(labelBorderPen, 0, 0, lblControlWidth,vlblControlHeight)
    e.Graphics.FillRectangle(labelBackColorBrush, 0, 0, vlblControlWidth,vlblControlHeight)
    e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
    e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
    
    
    vlblTransformX = 0
    vblTransformY = vlblControlHeight
    e.Graphics.TranslateTransform(vlblTransformX, vlblTransformY)
    e.Graphics.RotateTransform(270)
    e.Graphics.DrawString(labelText, Font, labelForeColorBrush, 0, 0)
    The label control draws properly etc.

    But if any of the text characters are a V or W there are funny jagged artifacts in those letter's angled lines.

    Does anyone know how to fix this? I tried looking up anti-aliasing etc.. but aside from changing the smoothing mode to antialias I couldn't find anything (changing this doesn't help a bit)

    Thanks,
    Nick

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Graphics.RotateTransform for vertical aligned Text

    Set the Graphics.TextRenderingHint to AntiAliasGridFit. That smooths the results of DrawString. The SmoothingMode is for drawn lines (e.g. DrawLine) and edges (e.g. FillEllipse). BB

    EDIT: Now I see you are already using ClearTypeGridFit. That ought to provide antialiasing too. You could try alternative settings, but maybe we have to look for another cause for the blocky edges.

  3. #3

    Thread Starter
    Hyperactive Member nickwrs's Avatar
    Join Date
    Jan 2000
    Location
    Atlanta, Ga
    Posts
    398

    Re: Graphics.RotateTransform for vertical aligned Text

    Here is the full code if it would help.
    *Edit* translated to VB.net
    Attached Images Attached Images   
    Attached Files Attached Files
    Last edited by nickwrs; May 12th, 2011 at 06:25 PM.

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Graphics.RotateTransform for vertical aligned Text

    You came too late with the VB version, but never mind, I braved the shark-infested waters of Csharp to take a look. TextRenderingHint.Antialias (without GridFit!) seems to give better diagonals and curves, but the straight lines become slightly irregular (on my screen). Sans-Serif fonts do better than Serif ones such as in your post above. Making the font slightly larger helps a lot -- 9 points is enough for Microsoft Sans Serif. I suspect that this is as good as you are going to get in WinForms. FWIW, WPF is reputed to be better at sub-pixel rendering. BB

  5. #5

    Thread Starter
    Hyperactive Member nickwrs's Avatar
    Join Date
    Jan 2000
    Location
    Atlanta, Ga
    Posts
    398

    Re: Graphics.RotateTransform for vertical aligned Text

    Thanks BB!
    I think you have the right of it; I'm going to leave this open for a bit more to see if anyone else has any other insight.

    I'll look into WPF.

    - Nick

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Graphics.RotateTransform for vertical aligned Text

    I can think of a couple of other possibilities that would be interesting to experiment with, although I don't have time at the moment,

    1. Create a text path with GraphicsPath.AddString, rotate the path with its own matrix argument, then render the text with Graphics.Drawpath or Graphics.FillPath.

    2. Render the text horizontally to a bitmap, then draw the bitmap rotated with Graphics.DrawImage.

    3. Render the text to a bitmap at double the target size, then draw the bitmap reduced to the target size with Graphics.DrawImage.

    I would be surprised if 1 offers much if any benefit, but I think 2 combined with 3 could well give an improved result for small text.

    BB

  7. #7
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Graphics.RotateTransform for vertical aligned Text

    I've not had much success with vertical rendering of text, not that I have done it much. However, my preference is to render text to an image and draw a rotated image. It seems to work for me, anyway, since I'm not a big fan of vertical text so don't do much of it.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  8. #8

    Thread Starter
    Hyperactive Member nickwrs's Avatar
    Join Date
    Jan 2000
    Location
    Atlanta, Ga
    Posts
    398

    Re: Graphics.RotateTransform for vertical aligned Text

    Hi all; it seems that writing to a bitmap and using the bitmap.rotate method seems to work much better... I can't for the life imagine why it would be different but it is. Cheers! Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width