views:

35

answers:

0

I was reading this article on warping text to splines and decided to play around with GraphicsPath.AddString which I had never used before.

I created a simple test Control to compare the three methods of drawing text: GraphicsPath.AddString, TextRenderer.DrawText, and Graphics.DrawString.

Here is the OnPaint method of my control.

    protected override void OnPaint(PaintEventArgs pe)
    {
        base.OnPaint(pe);

        const string text = "Normal";
        const int fontSizePixels = 14;

        using (var path = new GraphicsPath())
        {
            using (var font = new Font("Arial", fontSizePixels, FontStyle.Regular, GraphicsUnit.Pixel))
            {
                pe.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                pe.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                pe.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                pe.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                //GraphicsPath
                path.AddString(
                    text,
                    font.FontFamily,
                    (int) font.Style,
                    font.Size,
                    new PointF(0, 0),
                    StringFormat.GenericTypographic
                );

                pe.Graphics.FillPath(Brushes.Black, path);

                //TextRenderer
                TextRenderer.DrawText(
                    pe.Graphics,
                    text,
                    font,
                    new Point(0, fontSizePixels),
                    Color.Black
                    );

                //DrawString
                pe.Graphics.DrawString(
                    text,
                    font,
                    Brushes.Black,
                    new PointF(0, 2 * fontSizePixels)
                    );
            }
        }
    }

What I found is that for small font sizes, the GraphicsPath.AddString method produces the worst output. However, for large font sizes it looks the smoothest to me.

14px Arial

alt text

200px Arial

alt text

My question is, are there any settings or tricks I can use to make GraphicsPath.AddString look good for small font sizes? Or does the fact that the OS no longer knows it is text mean it will always look poor? If the latter is the case, what is the point of the GraphicsPath.AddString method?

My environment is WinForms through .NET 2.0 on Windows 7 with ClearType on.