Kezza Kezza - 4 months ago 60
C# Question

Can you use a regular URL to create a new font family in WPF

Hi I wanted to use a font in WPF without downloading the ttf.
The documentation on FontFamily class implied that I can use a http address as the base Uri for my font, however it doesn't seem to be working and I cannot find anywhere any working examples of how to do this.

So my code looks something like this

var newFont = new FontFamily(new Uri("http://myfontservice/myFont.ttf#myFont"), "myFont");

This is the most complex Uri I have tried. I've also tried a load of variations around the use of the font name but nothing seems to work.

Any help would be greatly appreciated.

Also worth noting the font service is just a folder on a machine that has been exposed over IIs. So the fonts are there as ttf files and the URL, if used in a browser, will download the ttf file.

Jcl Jcl

It's not possible as you expect it. According to the MSDN:

Site of origin fonts: WPF applications do not allow a font reference to an http or ftp uniform resource identifier (URI).

I guess the only hope is downloading it to a temp file and use a file:// URI to load it