|
-
May 12th, 2011, 04:01 PM
#1
Thread Starter
Hyperactive Member
[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
-
May 12th, 2011, 04:21 PM
#2
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.
Last edited by boops boops; May 12th, 2011 at 04:32 PM.
-
May 12th, 2011, 05:37 PM
#3
Thread Starter
Hyperactive Member
-
May 12th, 2011, 07:08 PM
#4
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
Last edited by boops boops; May 12th, 2011 at 07:16 PM.
-
May 12th, 2011, 07:16 PM
#5
Thread Starter
Hyperactive Member
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
-
May 13th, 2011, 05:07 AM
#6
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
Last edited by boops boops; May 13th, 2011 at 05:15 AM.
Reason: typos, as usual
-
May 13th, 2011, 10:52 AM
#7
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."
-
May 13th, 2011, 01:31 PM
#8
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|