PavelTorgashov / FastColoredTextBox

Fast Colored TextBox for Syntax Highlighting. The text editor component for .NET.
Other
1.22k stars 465 forks source link

Suggestion: Text rendering quality #207

Open EJocys opened 4 years ago

EJocys commented 4 years ago

Hi Pavel,

Really great control.

I've noticed that text was not looking so great. To improve quality you could add two methods under public class TextStyle or some other class:

public static void ConfigureForText(Graphics gr)
{
    gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    // ClearTypeGridFit will make text look much better.
    gr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
    gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
    gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
}

public static void ConfigureForShapes(Graphics gr)
{
    gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
}

...and then consistently drawing switch style in the code by calling these methods:

// Instead of: gr.SmoothingMode = SmoothingMode.[AntiAliasing|HighQuality;
TextStyle.ConfigureForText(e.Graphics);

// Instead of: gr.SmoothingMode = SmoothingMode.None;
TextStyle.ConfigureForShapes(e.Graphics);

Kind Regards, Evaldas Jocys