tags:

views:

59

answers:

1

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.

+1  A: 

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.

Hans Passant
Thanks for your suggested explanation, this *does* make sense. And yes, it does kill my plan. I may have to come up with another solution.
Sio
For anyone experiencing the same problem - I fixed this issue by using the lite version of Type 2.2 to change the family name of the font family from `Myriad Condensed Web` to `Myriad Web`, which gives it the same name in GDI+ as it does in WPF. I'm wondering if WPF attempts to deduce the font family name by removing style attributes such as "condensed" from the name, where as GDI+ used the full given font name.
Sio
Maybe it's a good idea if you document what "Type 2.2" means to backup your comment. That's not a common term that I've ever heard before. Just me though.
Hans Passant
Good point. Type Lite 2.2 was the only piece of freeware I could find that allowed me to change the font family name of a font and save it - http://www.cr8.netfirms.com/typelight.html
Sio