WPF Blurry fonts issue- Solutions

WpfFonts

Wpf Problem Overview


Problem is described and demonstrated on the following links:

Explanation: Text Clarity in WPF. This link has font comparison.

I would like to collect all possible solutions for this problem. Microsoft Expression Blend uses WPF but fonts look readable.

  • Dark background as in Microsoft Expression Blend
  • Increasing the font size and changing the font (Calibri ... ) [link]
  • Embed windows forms [link]
  • Use GDI+ and/or Windows Forms TextRenderer class to render text to a bitmap, and then render that bitmap as a WPF control. [link]

Are there any more solutions?

This is going to be fixed in VS2010 (and WPF4) beta 2

IT LOOKS LIKE IT HAS BEEN FINALLY SOLVED !

Scott Hanselman's ComputerZen.com: WPF and Text Blurriness, now with complete Clarity

Wpf Solutions


Solution 1 - Wpf

.NET 4 finally has a solution to WPF's poor text rendering quality, but it is well-hidden. Set the following for every window:

TextOptions.TextFormattingMode="Display"

Default value is "Ideal" which is not at all what the name implies.

There are two other options in TextOptions, namely TextHintingMode and TextRenderingMode, but they both have sensible defaults.

Solution 2 - Wpf

Technical background

There is a in-depth article about WPF Text rendering from one of the WPF Text Program Managers on windowsclient.net: Text Clarity in WPF.

The problem boils down to WPF needing a linearly scaling font-renderer for smooth animations. Pure ClearType on the other hand takes quite a bit of freedom with the font to push vertical stems into the next pixel.

The difference is obvious if one compares the classic "cascade" pattern. WinForms on the lower left side, WPF on the top right side:

https://club.black.co.at/david/pics/Fontcascade.png" width="640"/>

While I'm no fan of WPF's font rendering idiosyncrasies either, I can imagine the clamor if the animations would jump like they do in the Winforms cascade.

Playing with the registry

Of special interest to me was the link to the MSDN article "ClearType Registry Settings", which explains the possible user-side adjustments in the registry:

  • ClearType level: amount of subpixel hinting
  • Gamma level
  • Pixel structure: how the color stripes in a display-pixel are arranged
  • Text contrast level: adjusts the width of glyph stems to make the font heavier

Playing around with these settings didn't really improve the underlying problem, but can help by reducing the color bleeding effect for sensitive users.

Another approach

The best advice the Text Clarity article gave was increasing the font size and changing the font. Calibri works for me better than the standard Segoe UI. Due to its popularity as web font, I tried Verdana too, but it has a nasty jump in weight between 14pt and 15pt which is very visible when animating the font size.

WPF 4.0

WPF 4 will have improved support for influencing the rendering of fonts. There is an article on the WPF Text Blog explaining the changes. Most prominently, there are now (at least) three different kinds of text rendering:

text rendering comparison

<grumble>That should be enough rope for every designer.</grumble>

Solution 3 - Wpf

I encountered a problem the other day when I used a border which had a DropShadowEffect applied. The result was that all text inside that border was extremely blurry. It doesn't matter if text was inside other panels or directly under the border - any text block that is child of parent that has an Effect applied seems to be affected.

The solution to this particular case was to not put stuff inside the border that has effects, but instead use a grid (or anything else that supports putting content on top of each other) and place a rectangle in the same cell as the text (i.e. as a sibling in the visual tree) and put the effects on that.

Like so:

<!-- don't do this --->
<Border>
     <Border.Effect>
          <DropShadowEffect BlurRadius="25" ShadowDepth="0" Opacity="1"/>
     </Border.Effect>
     <TextBlock Text="This Text Will Be Blurry" />
</Border>

<!-- Do this instead -->
<Grid>
  <Rectangle>
     <Rectangle.Effect>
          <DropShadowEffect BlurRadius="25" ShadowDepth="0" Opacity="1"/>
     </Rectangle.Effect>
  </Rectangle>
  <TextBlock Text="This Text Will Be Crisp and Clear" />
</Grid>

Solution 4 - Wpf

This is going to be fixed in VS2010 (and WPF4) beta 2:

http://blogs.msdn.com/text/archive/2009/08/24/wpf-4-0-text-stack-improvements.aspx"> https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/text/WindowsLiveWriter/WPF4.0TextStackImprovements_12DE7/Magna%20Carta%20Ideal%20vs%20Display%208pt%20annotated_4.png"/></a>

Solution 5 - Wpf

I don't see it as a bug, but the default configuration is indeed very annoying. Here's a comparision of all the combinations of

TextOptions.TextRenderingMode
TextOptions.TextFormattingMode
RenderOptions.ClearTypeHint

SnapToDevicePixels doesn't make any differente in text rendering.

http://i.stack.imgur.com/cS3S2.png

I prefer:

TextOptions.TextRenderingMode="Auto"
TextOptions.TextFormattingMode="Ideal"
RenderOptions.ClearTypeHint="Auto"

where vertical lines are never blurry.

The font used is Open Sans Light, that can be really beautifull if it's well used, like in latest TeamViewer.

For those using Mahapps.Metro, the problem is the TransitioningContentControl https://github.com/MahApps/MahApps.Metro/issues/889

Solution 6 - Wpf

SnapToDevicePixels only applies to WPF shapes (lines etc), not to text renderer.

There is no known workaround to this issue. According to Microsoft, the behavior is "by design".

Also see http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5289ee56-6d06-4f66-84f2-69865b6dc401/">this</a> thread on Microsoft forums discussing the problems - it has gotten a few replies from MS guys which clarify their position on the issue.

Solution 7 - Wpf

From a developer's point, the only known "workaround" to date is to use GDI+ and/or Windows Forms TextRenderer class to render text to a bitmap, and then render that bitmap as a WPF control. Aside from obvious performance implications, this doesn't alleviate the problem for existing applications.

I have now created a Microsoft Connect ticket for this issue (to my surprise, despite all the negativity, there was no actual bug report in the designated tracker).

Since that is one of the official channels of communicating requests and questions to Microsoft, I would advise also going through it for a quicker answer. At least, if you wish for the issue to be addressed one way or another, voting for that ticket there and/or validating the issue will help to draw the attention of Microsoft PMs and engineers to this problem, and possibly raise its perceived priority.

Solution 8 - Wpf

Just tried out VS2010 beta, which is all done in WPF, and it suffers BADLY from the blurry-font issue. Particularly on tooltips.

That seems to give some evidence that WPF4 will in fact not solve the problem (if anything it looks worse)

Solution 9 - Wpf

Wow, I can't believe I finally got my WPF fonts readable. And I also can't believe there is no option dialog to make these changes easy while the default values are horrible on my display.

These registry settings (in decimal) worked for me and come closest to my regular cleartype font:

  • ClearTypeLevel: 10 (mostly greyscale aliasing)
  • GammaLevel: 1300 (higher gamma made the font too thin and I was seeing the colors in the aliasing)

Solution 10 - Wpf

They say "SnapToDevicePixels = true" works, but I've never seen any good results.

I combat the blurred text by switching to a different font.

Obviously this is not a solution to the problem, however this is how I've worked around it.

Solution 11 - Wpf

If you prefer to use a C# base class to customizing windows for your app (or now have a reason to), here's how you set can set the text formatting to use the appealing Display mode:

public class SnappyWindow : Window
{
    public SnappyWindow()
    {
        SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Display);
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobert VukovićView Question on Stackoverflow
Solution 1 - WpfHelge KleinView Answer on Stackoverflow
Solution 2 - WpfDavid SchmittView Answer on Stackoverflow
Solution 3 - WpfIsak SavoView Answer on Stackoverflow
Solution 4 - WpfPavel MinaevView Answer on Stackoverflow
Solution 5 - WpfGabrielView Answer on Stackoverflow
Solution 6 - WpfPavel MinaevView Answer on Stackoverflow
Solution 7 - WpfPavel MinaevView Answer on Stackoverflow
Solution 8 - WpfOrion EdwardsView Answer on Stackoverflow
Solution 9 - WpfVVSView Answer on Stackoverflow
Solution 10 - WpfInisheerView Answer on Stackoverflow
Solution 11 - WpfEdward BreyView Answer on Stackoverflow