gpt4 book ai didi

WPF 字体质量

转载 作者:行者123 更新时间:2023-12-02 11:58:26 26 4
gpt4 key购买 nike

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

字体质量在某些字体大小下会提高,例如FontSize="48"(我认为相当于 36pt),但使用有限数量的字体大小并不总是实用。

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

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

考虑到质量的提高,我很好奇为什么 WPF 不对所有文本执行此操作,还是性能下降?我正在考虑创建一个全局样式以将其应用于所有控件,否则这会导致问题吗?

(我尝试上传屏幕截图,但必须以低质量存储图像,而且您无法真正找出字体问题)。

最佳答案

这是blog post WPF Text 团队撰写了有关此功能的文章。

关于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.

由于这些属性是 .NET 4.0 中的新属性,因此它们将原始 WPF 算法保留为默认值,即理想模式。

对于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.

由于 Auto 是默认值,因此您通常会获得 ClearType 渲染。

现在,因为这些是附加属性,并且它们继承,所以您只需在根Window 处设置它们即可。无需创建一堆 Style

关于WPF 字体质量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13138299/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com