TextOptions.TextFormattingMode affecting bold text

I had a problem , as a result of which the font density of some Bold text reduced the size of the font weighted by the regular font. I decided that this is because I have the TextFormattingMode "Display" parameter set; the problem does not occur if the TextFormattingMode parameter is set to "Ideal".

For example, the following code:

<Label FontFamily="Calibri" FontSize="12" FontWeight="Bold" Content="This is some test text" TextOptions.TextFormattingMode="Ideal"/> <Label FontFamily="Calibri" FontSize="12" Content="This is some test text" TextOptions.TextFormattingMode="Ideal"/> <Label></Label> <Label FontFamily="Calibri" FontSize="12" FontWeight="Bold" Content="This is some test text" TextOptions.TextFormattingMode="Display"/> <Label FontFamily="Calibri" FontSize="12" Content="This is some test text" TextOptions.TextFormattingMode="Display"/> 

Produces the following:

Results of XAML when running

If the font size is up to about 14 for the last two labels, the bold text will be larger than regular weighted text.

My question is: is there a parameter that I can use to have 12-point bold text with the TextFormattingMode parameter set to "Display", which is the same size / slightly larger than regular weighted text?

+4
source share
2 answers

The problem is not that the bold text is too short, but that the plain text is too long.

The story behind this, WPF was originally shipped in .NET 3.0, which only supported the β€œideal” mode for scaling text. This mode supports independent scaling of text with independent resolution, the line of text will have a predicted length in inches on different display devices with different dots per inch resolution. This did not work out well; it caused widespread complaints from WPF programmers who did not like the blurry text that it produced. This is visible on the screen. Please note that the left stem of the bold letter m is too thick in ideal mode, but not in display mode.

In .NET 4.0, the WPF team supported a new way to render text called Display. What makes the text the way GDI does, by applying font hint rules to adjust the shape of the letter so that it matches better with the pixel grid of the monitor. This tends to stretch the letters, especially when their stem has only one pixel. The smaller the point size, the more pronounced it is. Because of this, the text is read with a high degree of readability, but true rendering with independent resolution is lost.

Winforms also went through a similar evolution, starting with Graphics.DrawString () and ending with TextRenderer.DrawText ().

This WPF Team Blog Post contains information.

So the answer to your question is missing.

+8
source

Unfortunately, you have already answered your question. The answer is no. I do not know why this is happening. I looked at it and pulled it into SNOOP, and of course it reduces the size.

It seems that all font settings between 10.5 and 12.4 have this problem. Fonts 8, 9 or 10, 10.4 and 12.5, 13, 14 do not.

It seems like time to contact Microsoft. Send an error.

In addition, this is due to the Windows display settings. When I switched the display settings from 100% to 125%, the problem changed. Now they look about the same, but no less.

+1
source

Source: https://habr.com/ru/post/1442992/


All Articles