Robert Vuković
Robert Vuković

Reputation: 4688

WPF Blurry fonts issue- Solutions

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.

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

Upvotes: 158

Views: 70331

Answers (12)

Pavel Minaev
Pavel Minaev

Reputation: 101565

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

enter image description here

Upvotes: 10

David Schmitt
David Schmitt

Reputation: 59346

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:


(source: black.co.at)

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
(source: windows.net)

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

Upvotes: 109

erez
erez

Reputation: 35

What worked for me (As done in tweetz and after looking again here, as Pat stated in his comment) is setting UseLayoutRounding="True" in my window.
UseLayoutRounding documentation rounds the different layout sizes in order to draw on the device pixels. As the documentation states:

Drawing objects on pixel boundaries eliminates the semi-transparent edges that are produced by anti-aliasing when an edge falls in the middle of a device pixel.

A good answer that explains the difference between UseLayoutRounding and SnapToDevicePixels property is this.

Upvotes: 1

Edward Brey
Edward Brey

Reputation: 41648

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);
    }
}

Upvotes: 1

Helge Klein
Helge Klein

Reputation: 9085

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

Upvotes: 139

Gabriel
Gabriel

Reputation: 2190

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.

https://i.sstatic.net/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

Upvotes: 7

Isak Savo
Isak Savo

Reputation: 35884

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>

Upvotes: 47

Pavel Minaev
Pavel Minaev

Reputation:

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.

Upvotes: 6

VVS
VVS

Reputation: 19604

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)

Upvotes: 4

Orion Edwards
Orion Edwards

Reputation: 123642

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)

Upvotes: 4

Pavel Minaev
Pavel Minaev

Reputation:

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 this thread on Microsoft forums discussing the problems - it has gotten a few replies from MS guys which clarify their position on the issue.

Upvotes: 6

Inisheer
Inisheer

Reputation: 20794

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.

Upvotes: 3

Related Questions