开发者

Where does WPF's FontFamily.Source retrieve its value from?

开发者 https://www.devze.com 2023-01-14 03:06 出处:网络
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 Windo

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 u开发者_开发技巧sing 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.


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.


I've found that blog post http://blogs.msdn.com/b/text/archive/2009/04/15/introducing-the-directwrite-font-system.aspx It seems that that method of family name conversion may be the way to do it right.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号