可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Problem is described and demonstrated on the following links:
- Paul Stovell WPF: Blurry Text Rendering
- www.gamedev.net forum
- Microsoft Connect: WPF text renderer produces badly blurred text on small font sizes
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
WPF 4.0 Text Stack Improvements
IT LOOKS LIKE IT HAS BEEN FINALLY SOLVED !
Scott Hanselman\'s ComputerZen.com: WPF and Text Blurriness, now with complete Clarity
WPF Text Blog: Additional WPF Text Clarity Improvements
回答1:
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:
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:
<grumble>That should be enough rope for every designer.</grumble>
回答2:
.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.
回答3:
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>
回答4:
This is going to be fixed in VS2010 (and WPF4) beta 2:
回答5:
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.
回答6:
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.
回答7:
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)
回答8:
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)
回答9:
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.
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
回答10:
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.