I’d like to load a font from an external server and once is loaded (I guess that’s necessary) use it to create a few textfields.
I’m trying:
font_uri = new Uri("http://localhost/assets/fonts/wingding.ttf");
bf_helvetica = new FontFamily(font_uri, "bf_helvetica");
TextBlock test_tb = new TextBlock();
test_tb.Text = "This is a test";
test_tb.FontSize = 16;
test_tb.Foreground = Brushes.Red;
test_tb.FontFamily = bf_helvetica;
stage.Children.Add(test_tb);
But it creates the textblock with the default font.
Any ideas?
Thanks in advance 🙂
If you can load it into a Stream, try using a PrivateFontCollection. Example code in my answer to another question.
EDIT: See System.Net.WebRequest.GetRequestStream, load the URI into a Stream, then load that Stream into the PFC as mentioned in the linked code.
Also, I’d save the file locally, and look for it there first, so you don’t have to download it every time you run the program.
EDIT AGAIN: Sorry, not WebRequest.GetRequestStream, you want WebResponse.GetResponseStream(). Here’s some sample code to do exactly what you’re looking for.