TextOptions.TextFormattingMode影响具有粗体字体重量的文本 [英] TextOptions.TextFormattingMode affecting text with bold font weight

查看:662
本文介绍了TextOptions.TextFormattingMode影响具有粗体字体重量的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从WPF团队有详细信息。



因此,您的问题的答案是否。 / p>

I've had a problem where making the font weight of some text Bold made it smaller than the Normal font weighted text. I've worked out that this is because I've got the TextFormattingMode set to "Display"; the problem doesn't occur if the TextFormattingMode 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:

If I up the font size to about 14 for the last two labels the bold text becomes larger than the normal weighted text.

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

解决方案

The problem is not that the bold text is too short, it is that the normal text is too long.

There's history behind this, WPF originally shipped at .NET 3.0 supporting only the "Ideal" mode for scaling text. This mode supports true resolution independent text scaling, a line of text will have a predictable length in inches on various display devices with different dots-per-inch resolution. This was not received well, it caused massive complaints from WPF programmers that didn't like the blurry text that this produces. This is visible in your screen-shot. Note how the left stem of the bold letter m is too fat in Ideal mode but not in Display mode.

At .NET 4.0, the WPF team supported a new way to render text, called "Display". Which renders text the way GDI does it, applying font hinting rules to tweak the letter shape so it coincides better with the pixel grid of the monitor. This tends to stretch the letters, especially when their stem only has a single pixel. The smaller the point size, the more pronounced this becomes. The text is highly readable because of it, but true resolution independent rendering is lost.

Winforms also went through a similar evolution, from Graphics.DrawString() to TextRenderer.DrawText().

This blog post from the WPF team has the details.

The answer to your question is thus No.

这篇关于TextOptions.TextFormattingMode影响具有粗体字体重量的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆