Lester's WPF\SL Blog

Simple, Easy & Beautiful

New WPF Features: TextFormattingMode for clear text

New WPF Features: TextFormattingMode for clear text

Rate This
  • Comments 9

This is part of a series on New WPF Features

Now there has been feedback since 3.0 that the WPF text doesnt render clearly when the fontsizes are smaller. So for .NET 4 we forked on this issue and fixed it by introducind the property TextOptions.TextFormattingMode. The default value is ideal which is what we have currently. The other option is Display and it makes small text look crisper and clear.

Lets see it in action

<StackPanel xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'

            xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>

            <TextBox TextOptions.TextFormattingMode="Ideal" FontSize="10">HELLO WORLD</TextBox>

            <TextBox TextOptions.TextFormattingMode="Display" FontSize="10">HELLO WORLD</TextBox>

           

            <TextBox TextOptions.TextFormattingMode="Ideal" FontSize="15">HELLO WORLD</TextBox>

            <TextBox TextOptions.TextFormattingMode="Display" FontSize="15">HELLO WORLD</TextBox>

</StackPanel>

See the difference :) ... also for asian characters the difference is very evident ..

Guidelines for this property 

Scenarios

Recommended Mode

Large Text (15pt+)

Ideal \ Display (users preference)

Transformed Text

Ideal

Zoomed Text

Ideal

Design Scenarios

Ideal

Small Text

Display

Share this post

 

  • Why not call it TextRenderingMode? Formatting sounds like some options for doing something like Console.WriteLine("Hello, {0}!", "Bob")..

  • I agree that calling it formatting is a little misleading.  It is a great feature though, thanks for the post!

  • Hi Lester,

    Are you saying that 14pt and below is 'small' text and so should be set to 'Display'?

    If the default is 'Ideal' could you implement some kind of implicit (app level) style to trigger to 'Display' if less than 15pt?

    Thanks

    John

  • John, currently we do not support the implicit switching.

    Ray\Graeme, thanks for the feedback on the naming.

    Your feedback will be conveyed to the respective teams for consideration.

  • I wholeheartedly agree with Ray and Graeme, having the word 'Formatting' in the name is very misleading.  TextRenderingMode is a much better name for this property.

  • I agree with previous posters about the naming. Also, is there a good explanation on why font rendering in WPF is so hard (from your perspective). There are lots of annoying issues with text rendering in WPF (this being on of them) and I am wondering why text rendering is so poor.

    Don't get me wrong I love WPF, and the text rendering isn't a major stumbling block for me, but it does seem odd that there are so many problems with it.

  • TextFormatting mode refers to how TextFormatter is created. It is happening before rendering. (http://msdn.microsoft.com/en-us/library/system.windows.media.textformatting.textformatter.aspx).

    Before dotnet 4.0, WPF uses ideal metric layout which preserves the shape of all glyphs even if this means not starting and/or ending a glyph on a pixel boundary (subpixel). This causes poor rendering results on the screen particularly for smaller text.

    For 4.0, we're introducing GDI compatiable way of creating TextFormatter (Display mode) besides the existing Ideal mode. GDI uses a text layout algorithm that slightly modifies glyph width and placement to make sure that glyphs start and end on pixel boundaries. This improves the clarity of each letter yet detracts from the ascetics of a carefully constructed font.

    For rending, we'll have three text rendering mode. They are ClearType, Grayscale, and Aliased. You can set it using the same logic TextOptions.TextRenderingMode="".

    For more details, you can read http://blogs.msdn.com/text/.

  • My bad. Thank you for your explanation Dennis. It's a nice feature. I'm always happy to know things are improving. Just expecting some magic..

  • No problem. It's great to have you guys:).

Page 1 of 1 (9 items)