WPF 的 FontFamily.Source 从哪里检索其值?

发布于 2024-09-17 20:06:23 字数 459 浏览 1 评论 0原文

我有两个使用相同数据创建 UI 的应用程序,一个使用 WPF,另一个使用 GDI。根据 Windows 中的字体名称属性,我使用的是一种名为 Myriad Condensed Web 的字体。我使用给定的字体名称实例化 System.Drawing.FontFamily 对象没有问题。但是,当我使用 WPF 的 System.Windows.Media.FontFamily 创建此字体时,我只能使用名称 Myriad Web 来完成。我在 Window 字体控制面板的字体属性中找不到对此值的引用。当我检查 System.Windows.Media.Fonts.SystemFontFamilies 时,Myriad Web 是 Source 属性的值。

所以我的问题是,WPF 从哪里获取这个值?为什么它与 GDI 给出的值不同?如何使用同一个字体名称为 GDI 和 WPF 实例化相同的字体?我想避免存储两个值 - 一个用于 GDI,另一个用于 WPF。

I have two applications that use the same data to create a UI, one is using WPF and the other is using GDI. I'm using a font called Myriad Condensed Web, according to the font name attribute in Windows. I have no problem instantiating the System.Drawing.FontFamily object using the given font name. However, when I create this font using WPF's System.Windows.Media.FontFamily, I can only do it using the name Myriad Web. I can't find a reference to this value anywhere in the font properties within Window's fonts control panel. When I inspect System.Windows.Media.Fonts.SystemFontFamilies, Myriad Web is the value of the Source attribute.

So my question is, where is WPF getting this value from? And why is it different to the value GDI is giving? And how can I instantiate the same font for both GDI and WPF using one font name? I want to avoid storing two values - one for GDI and one for WPF.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国产ˉ祖宗 2024-09-24 20:06:23

我不能 100% 确定发生了什么,但我有一个很好的理论。自 GDI+ 以来,字体技术已经取得了长足的进步,这可能是由于合并了 OpenType 支持的结果。 WPF 有 FontStretch 的概念,FontStretches 类定义了“Consensed”、“Medium”、“Expanded”等值。

此属性在旧代码中不可用,我认为 Windows 字体管理器合成字体系列名称以保持兼容。通过在常规姓氏中注入“Condensed”(等)。因此,请在心里删除这个形容词以获得 WPF 名称。当然,它确实会破坏你的计划,除非你考虑在代码中自己过滤它。

I'm not 100% sure about what's happening, but I have a good theory. Font technology has progressed considerably since GDI+, probably as a result of incorporating OpenType support. WPF has the notion of FontStretch, the FontStretches class defines values like "Consensed", "Medium", "Expanded" etc.

This property isn't available in legacy code, I think the Windows font manager synthesizes font family names to keep things compatible. By injecting "Condensed" (etc) in the regular family name. So, mentally remove this adjective to get the WPF name. It does kill your plan of course, unless you'd consider filtering it yourself in code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文