WPF字体质量 [英] WPF font quality

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

问题描述

我正在开发一个WPF应用程序,但是我注意到,在某些字体大小下,文本的渲染效果不如您在控制面板 - >字体中看到的示例。我正在使用大型的Segoe UI字体( FontSize =36),效果在直线上更​​明显。一个字母U可能比另一个稍微厚一些。
)。



在某些字体大小下, FontSize =48(我相信它相当于36pt),但使用有限的字体大小并不总是实际。 b

通过将以下属性应用于TextBlock,我可以提高字体质量: - $ /

$ p $ TextOptions。 TextFormattingMode =DisplayTextOptions.TextRenderingMode =ClearType

鉴于质量的提高,我很好奇要知道为什么WPF不会为所有文本执行此操作,还是会影响性能?我想创建一个全球风格,将其应用于所有控件,或这将导致一个问题?

(我试图上传一个截图,但SO必须存储图像在一个低质量,你不能真正的字体问题)。

解决方案

这是博客文章表示WPF文本团队写了关于这个功能。 $ b

注意 TextFormattingMode


理想自WPF引入以来,理想文本度量标准是用于
格式文本的度量标准。这些指标导致
字形的形状保持高保真度,从
字体文件的轮廓。当
创建字形位图或相对于每个
other定位字形时,不会考虑字形的最终放置位置。



显示在这种新格式模式下,WPF使用GDI
兼容的文本度量。这确保了每个字形的宽度为
多个整像素,并且位于整个像素上。使用
GDI兼容性文本度量也意味着字形大小和行
中断类似于基于GDI的框架。也就是说,glyph size
不是WPF使用的换行算法的唯一输入。
即使我们使用与GDI相同的指标,我们的换行也不会是
完全一样。


由于这些属性在.NET 4.0中是新的,所以它们保留了原始的WPF算法,默认情况下是理想模式。



对于 TextRenderingMode


自动设置已被
设置为在机器上明确禁用ClearType。


$ b

别名不会使用抗锯齿来绘制文本。 p>

灰度灰度抗锯齿将用于绘制
文本。

<


由于自动 c $ c>是默认的,你通常会得到 ClearType 渲染。

现在,因为这些是附加属性,而且它们,所以可以将它们设置在 Window 。不需要创建一堆样式 s。


I'm developing a WPF app but I've noticed that at certain font sizes the text doesn't render as nicely as the samples you see in Control Panel -> Fonts. I'm using large Segoe UI fonts (FontSize="36"), and the effect is more noticeable on the upright lines, e.g. a letter "U" might be slightly thicker on one side than the other. ).

The font quality improves at certain font sizes, e.g. FontSize="48" (which I believe is the equivalent of 36pt), but using a limited number of font sizes isn't always practical.

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

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

Given the improvement in quality I'm curious to know why WPF doesn't do this for all text, or is it down to performance? I was thinking of creating a global style to apply this to all controls, or will this cause a problem?

(I tried uploading a screenshot but SO must store images at a low quality, and you couldn't really make out the font problem).

解决方案

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

Note for the TextFormattingMode:

Ideal Ideal text metrics are the metrics which have been used to format text since the introduction of WPF. These metrics result in glyphs’ shapes maintaining high fidelity with their outlines from the font file. The glyphs’ final placement is not taken into account when creating glyph bitmaps or positioning the glyphs relative to each other.

Display In this new formatting mode, WPF uses GDI compatible text metrics. This ensures that every glyph has a width of multiple whole pixels and is positioned on whole pixels. The use of GDI compatible text metrics also means that glyph sizes and line breaking is similar to GDI based frameworks. That said, glyph sizes are not the only input into the line breaking algorithm used by WPF. Even though we use the same metrics as GDI, our line breaking will not be exactly the same.

Since these properties are new in .NET 4.0, they kept the original WPF algorithm as default, which is Ideal mode.

For the TextRenderingMode

Auto This mode will use ClearType unless system settings have been set to specifically disable ClearType on the machine.

Aliased No antialiasing will be used to draw text.

Grayscale Grayscale antialiasing will be used to draw text.

ClearType ClearType antialising will be used to draw text.

Since Auto is default, you will generally get ClearType rendering.

Now, because these are attached properties, and they inherit, you can just set them at the root Window. No need to create a bunch of Styles.

这篇关于WPF字体质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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