WPF does not display Windows OpenType font name

I cannot figure out how to correctly determine the specific OpenType font in WPF (.NET 4.5 / VS2012 / Windows 8). I have a font installed on my computer called "DINPro-BlackItalic".

File Name: DINPro-BlackItalic.otf

Windows reports font name: DINPro-BlackItalic

Windows Font preview for DINPro-BlackItalic

In WPF, I am doing something simple, for example:

<TextBlock Text="This is a sample sentence in DINPro-BlackItalic" FontFamily="DinPro-BlackItalic" FontSize="24" /> 

or FontFamily="#DinPro-BlackItalic"

This does not work (obviously not in italics), and it reverts to the default font. I tried many other options that work for other fonts in the font directory.

For example, Comic Sans works: FontFamily="Comic Sans MS" (awesome ...)

Now here's why I'm really confused: If I just guess another way to renumber the font name, it displays correctly!

It works: FontFamily="Din Pro Black Italic"

In short, here is a screenshot of the various FontFamily settings in WPF: Several FontFamily settings in WPF

Two questions:

1) How should I guess how to pass WPF this font correctly? It should have some canonical name registered somewhere, but it does not appear in the file name, file properties, or font name that Windows reports after it parsed the file.

2) What's worse, if I try to display the same font in a desktop application and on the Internet, browsers such as Chrome on Windows and even IE expect a “DINPro-BlackItalic” and will not display a delayed version of the name. It seems that WPF and Windows browsers make mutually exclusive decisions about which font name to use for indexing fonts. How do I get around this for custom fonts?

DINPro Font rendering in Chrome and IE

+7
fonts wpf render
source share
4 answers

You can pack the font using the application, and you can take it from the project directory. Say if you put a font inside the Fonts Directory in Project.

You can add the following:

 <TextBlock FontFamily="/Fonts/DINPro-BlackItalic.otf#DinPro-BlackItalic"/> 

So, you can be sure that the font will be deployed along with the application.

+4
source share

Ok, so I think I found a solution.

 <TextBlock FontFamily="/Fonts/DINPro-BlackItalic.otf#Din Pro"/> 

or

 <TextBlock FontFamily="/Fonts/DINPro-BlackItalic.otf#Din Pro Black Italic"/> 

Didn't try your code, but it seems to work for me .. Link to file path + fontname

Opentype files have a common name that they use. And here it becomes difficult, because you can see this name only if you install the font on your computer and check it in familytree. As you have already shown in your question:

 FontFamily="Din Pro Black Italic" 

This is my experience, and not 100% sure that I am right, only that it works for me :)

+1
source share

For WPF it is better to try it with the constructor to select the font for Textblock

For browsers, you can try it using a shortcut or any other user interface controls.

0
source share

The syntax that works for me is:

 /{Application Name};component/{Font Folder in Project}/#{Font Name (not filename)} 

Example:

 /ApplicationName;component/Fonts/#Proxima Nova Lt 
0
source share

All Articles