WPF Font Quality

I am developing a WPF application, but I noticed that with certain font sizes, the text does not display as well as the samples that you see in the control panel β†’ Fonts. I use large Segoe UI fonts ( FontSize="36" ), and the effect is more noticeable on vertical lines, for example. the letter "U" may be slightly thicker on one side than the other. )

Font quality improves with certain font sizes, for example. FontSize="48" (which, in my opinion, is equivalent to 36pt), but using a limited number of fonts is not always practical.

I can improve the quality of the font by applying the following properties to the TextBlock: -

 TextOptions.TextFormattingMode="Display" TextOptions.TextRenderingMode="ClearType" 

Given the improvement in quality, I am curious to know why WPF does not do this for all text, or does it come to performance? I was thinking of creating a global style to apply this to all controls, or would this cause a problem?

(I tried to download the screenshot, but SO should keep the images in poor quality, and you could not deal with the font problem).

+5
fonts wpf font-size
source share
2 answers

Here is a post that the WPF Text team wrote about this feature.

Note for TextFormattingMode :

Ideal Ideal text metrics are metrics that have been used to format text since the introduction of WPF. These metrics lead to glyphs retaining high precision with their outlines from the font file. The final placement of glyphs is not taken into account when creating bitmaps of glyphs or positioning glyphs relative to each other.

Display In this new formatting mode, WPF uses GDI compatible text metrics. This ensures that each glyph has a width of a few integer pixels and fits in whole pixels. The use of GDI-compliant text metrics also means that the size and line glyph violation is similar to the framework based on GDI. However, glyph sizes are not the only input to the line break algorithm used by WPF. Despite the fact that we use the same indicators as GDI, to be exactly the same.

Since these properties are new in .NET 4.0, they by default retained the original WPF algorithm, which is ideal.

For TextRenderingMode

Auto This mode will use ClearType if there were no system settings to specifically disable ClearType on the machine.

Alias ​​Anti- aliasing will not be used to create text.

Grayscale Smoothing in grayscale will be used to draw text.

ClearType ClearType erase is used to create text.

Since Auto is the default, you usually get a ClearType rendering.

Now, since they are attached properties, and they inherit , you can simply install them in the root directory of Window . No need to create a bunch of Style s.

+7
source share

I noticed minor performance issues when working with large amounts of data (over 10,000 items) when ClearType is enabled. Changing the TextFormattingMode display mode does not have a noticeable effect on performance.

This suggests that in all my WPF applications, I use global styles to improve text rendering if the performance impact is not large enough to make the user interface sticky.

0
source share

All Articles