New WPF 4.0 Features

WPF 4.0 Beta1 was released last month. While many exciting features were included in Beat1, there was no work targeting text, flow, or layout. This will all be reversed with WPF Beat2. Below is a brief overview for each of the features included in Beta2 which target text, flow, or layout. I will make subsequent posts giving more detail about each feature, including API details. For now, I just want to let everyone know that great features are coming!

 

 

Text clarity improvements

In previous versions of WPF, all text is formatted without specifically accounting for pixel boundaries. This approach provides uniform scalability and ensures that glyph outlines adhere to font specifications. Unfortunately, small text appears blurry when it is rendered across pixel boundaries, and this has affected our customers. In the past, we have only been able to say “we are working on a fix.” Now I can tell you that this is solved in WPF4.0!

 

As of Beta2, WPF provides developers with the ability to control how text is both formatted and rendered. Text can now be formatted to either strictly adhere to font specifications or fall on pixel boundaries. This new option allows text to be rendered more clearly at the slight expense of glyph shape and position.

 

The option to set the rendering mode for text (eg, aliased, grayscale, ClearType) is also conveniently exposed. In most situations ClearType is an obvious win; however ClearType can degrade the user experience on CRTs and for people whose eyes are color sensitive. In the past, WPF forced all apps to use ClearType. Now, developers can choose between two additional rendering modes.

 

 

A Bindable Run

The inability to bind Run.Text has forced many people to create home brew solutions. In WPF4.0, Run.Text has been converted to a Dependency Property. Run.Text now enjoys most of the benefits that come with this change, such as the ability to be bound, styled, and templated.

 

One-way binding is fully supported. Unfortunately, we did not have time to implement full support for two-way binding. This scenario is supported if a run is only modified through the property system, but not when the run is modified via a RichTextBox or the text object model.

 

 

LayoutRounding

WPF’s layout engine frequently causes subpixel rendering along element boundaries. This can lead to both rendering artifacts and blurry rendering, as antialiasing causes subpixel rendered elements to be displayed over multiple actual pixels. A classic example of this problem is small icons which get blurred because the icon images are placed on subpixel boundaries. Enabling LayoutRounding forces the WPF layout engine to place elements on whole pixel boundaries, thus removing most of the rendering artifacts caused by this problem.

 

 

Caret and Selection Brush

The default visual appearance of most objects in WPF can be easily tweaked or completely changed. This provides developers far greater power over the visual look of an application than ever before. Facilitating the creation of highly customized apps has become a major adoption point for WPF. Despite WPF’s extensibility, the color of text selection and carets in text boxes and document viewers remains baked into the framework. WPF now exposes properties to control the brushes used to paint text selection and carets.

 

 

-Chipalo

Comments

  • Anonymous
    June 24, 2009
    PingBack from http://www.wiredprairie.us/blog/index.php/archives/801

  • Anonymous
    July 06, 2009
    The comment has been removed

  • Anonymous
    July 07, 2009
    WOW, look forward to test the text improvement. I use text animation for entertainment applications, and this will be awsome!!

  • Anonymous
    July 11, 2009
    I was unpleasantly surprised by Visual Studio 2010 Beta1 as it doesn't support the Courier font any more. The reason turned out to be that it uses WPF, which doesn't support raster fonts. So I tried to find another font that works for me. There's not that much choice for fixed-width fonts - Consolas, Courier, Courier New, Fixed Sys, Lucida Console, MS Mincho and Terminal. Courier, Fixed Sys and Terminal are raster fonts so they don't count. MS Mincho is waaay too narrow for source code. Next I tried Consolas, Courer New and Lucida Console but they all felt weird. Aside from Consolas and Courier New wasting too much space between the lines and Lucida Console being just too fancy, there was something else. I looked closer to see what really bothered me and I think I got it. All of these fonts looked blurry even when I disable the font smoothing from the system settings. This makes the vertical parts of the glyphs wash out and the horizontal parts stand out. Will the new WPF 4.0 solve this? And will it be solved in time to affect Visual Studio 2010? Also, can somebody recommend a fixed-width vector font that is suitable for coding? Something that looks crisp and legible at size 10 and doesn't waste space between the lines? Ivo

  • Anonymous
    July 16, 2009
    Any chance of a screenshot of the text quality improvements?  As they say, a picture's worth a thousand words...

  • Anonymous
    July 17, 2009
    Two questions,

  1. Which text rendering option I should take if I need to get the most clear and smooth texts? Grayscale? I am talking about a WinForm like quality.
  2. Will Silverlight's text rendering be improved at the same time? I know there is ClearType support in Silverlight 3 now, but the actual clarity is still far away from satisfaction yet.
  • Anonymous
    July 17, 2009
    Yes, screenshots and API details are on their way.

  • Anonymous
    August 08, 2009
    Fantastic news! I find that smoothed text can be difficult to read, so hearing that crisp fonts (ie: simple rasterization without antialiasing) are available on the WPF is truly joyous news! Huzzah!

  • Anonymous
    August 12, 2009
    Is the screenshot post still on its way?  I take it we should be looking out for the post on the DirectX dev blog rather than here, but it's looking awfully quiet over there! Hopefully it won't be too long until .NET 4.0 beta 2 is out and and we can see the text rendering improvements first hand.

  • Anonymous
    August 21, 2009
    The comment has been removed

  • Anonymous
    October 19, 2009
    Does anybody know if RichTextbox will support multi-column editing and displaying page-breaks more "word like editing"? brgds Martin

  • Anonymous
    October 26, 2009
    The comment has been removed

  • Anonymous
    November 22, 2009
    Will the new text clarity improvements help with text in a layered window?  Currently if you have a window with the AllowsTransparency=true, you get into this whole air space issue, and if I read correctly, WPF chose the Application-Provided Content mode, which naturally allows WPF's anti-aliased rendering to work on the layered window too, but the text in a window that allows transparency ends up looking fuzzy.  You can verify this by turning off AllowsTransparency, the font (Segoe UI) renders crisp! Will this be fixed?

  • Anonymous
    December 04, 2009
    Martin – Those features are not planned for .Net4.0 Brett B – To render ClearType, WPF must know the final background color for text when we rasterizing the glyph bitmaps. If we do not know this, we will not be able to correctly apply the ClearType algorithm.  Basically this means that WPF cannot render ClearType text on a transparent object.  Technically, WPF cannot render ClearType when an object introduces an intermediate render target. Unfortunately, not all objects which force intermediate render targets are necessarily transparent (eg PopUp). In these cases ClearType is over aggressively disabled by WPF. The property RenderOptions.ClearTypeHint has been introduced in .Net4.0 to help combat this problem. Setting ClearTypeHint to “Enabled” on an object essentially tells WPF that this object is opaque and rendering ClearType is safe.  I’ll do a more thorough blog post on this topic in the near future.