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?

post-120702-0-69331000-1446532184_thumb.

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
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); 
    // Reset the destination canvas
    dst.CopySurface(src,rect.Location,rect);
    // 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;
            break;
        case 1: // anti-alias
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            break;
        case 2: // cleartype
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            break;
    }
    // Be sure to clip to our ROI
    g.Clip = new Region(rect);
    // Create a font from user selection
    Font SelectedFont;
    try
    {
        SelectedFont = new Font(Amount2.Name, Amount3);
    }
    catch
    {
        // 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

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

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

forumSig_bmwE60.jpg

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...

 

Quote

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.

Guest
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.

 Share

×
×
  • Create New...