Jump to content

How to enable ClearType?

Recommended Posts

I can see ClearType GUI font rendering at site screenshots, but it won't work for my Paint.NET.

I use Windows 7 x64 and Paint.NET 4.0.6. ClearType is turned on in my system settings, and its works fine for most of software, including my personal .NET programs. Is it possible to activate it for this editor somehow?


Link to comment
Share on other sites

Here is a CodeLab script to do it:

// Title: BoltBait's Render Text Sample
// Author: BoltBait
// Submenu: Render
// Name: Text
// URL: http://www.BoltBait.com/pdn
#region UICode
MultiLineTextboxControl Amount1 = ""; // [1,32767] Text
FontFamily Amount2 = new FontFamily("Arial"); // Font
IntSliderControl Amount3 = 12; // [10,72] Size
RadioButtonControl Amount4 = 0; // [1] Smoothing|None|Anti-Alias|ClearType
ColorWheelControl Amount5 = ColorBgra.FromBgr(0,0,0); // Color
PanSliderControl Amount6 = Pair.Create( 0.0 , 0.0 ); // Location

void Render(Surface dst, Surface src, Rectangle rect)
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); 
    // Reset the destination canvas
    // Determine where the text will be written
    int column = (int)Math.Round(((Amount6.First + 1) / 2) * (selection.Right - selection.Left));
    int row = (int)Math.Round(((Amount6.Second + 1) / 2) * (selection.Bottom - selection.Top));
    // Create a brush and graphics surface to write on
    SolidBrush Brush1 = new SolidBrush(Amount5.ToColor());
    Graphics g = new RenderArgs(dst).Graphics;
    // specify smoothing mode
    switch (Amount4)
        case 0: // none
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
        case 1: // anti-alias
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
        case 2: // cleartype
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
    // Be sure to clip to our ROI
    g.Clip = new Region(rect);
    // Create a font from user selection
    Font SelectedFont;
        SelectedFont = new Font(Amount2.Name, Amount3);
        // If font creation fails, use Arial font
        SelectedFont = new Font("Arial", Amount3);
    // Write our text to the canvas
    g.DrawString(Amount1, SelectedFont, Brush1, column, row);
  • Upvote 1
Link to comment
Share on other sites

The Text Tool doesn't use ClearType, and you can't enable it to do so. ClearType can only render on top of opaque content, and layers in Paint.NET have an alpha channel. It would be really confusing if the Text Tool didn't work when used on a layer that isn't completely opaque, or if it reverted to non-ClearType without telling you. It is also very useful to have text on its own layer, and requiring text to be on a layer that's opaque kinda defeats the purpose.


I've always wanted to have this workable, but the obstacles just don't justify the engineering cost.


Also, FWIW, GDI+'s text rendering is pretty bad :( (referring to BoltBait's code sample). Also, the following code:


Graphics g = new RenderArgs(dst).Graphics;


is incorrect. You need to hold on to the RenderArgs for the duration of your method, otherwise it will destroy the Graphics. So, this code has a race condition with the garbage collector.


I recommend this instead,

using (RenderArgs ra = new RenderArgs(dst))
    Graphics g = ra.Graphics;

I also recommend wrapping your other disposable resources (e.g. brushes, and any other GDI+ object) with a "using" block. Otherwise it can become a significant performance issue.

  • Upvote 4

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html


Link to comment
Share on other sites

  • 5 years later...
5 hours ago, DavidP said:

In the documentation it says that ClearType is available as one of three options for text antialiasing.


That's not what is says...



There are three text rendering modes: Smooth, Sharp (Modern) & Sharp (Classic). These correspond to DirectWrite rendering modes of Outline, ClearType Natural Symmetric, and GDI Classic, respectively.


The key word here is correspond ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...