Introduction
If you want to use non-standard fonts in your application, you can embed them in your application assembly. That way, your application never has a problem finding the font you want to use. In this article we will see all how we can make this happen.
Crating Silverlight Project
Fire up Visual Studio 2008 and create a Silverlight Application. Name it as FontEmbeddingInSL3.
As you know a Silverlight application always runs in client machine, so based on the client machine settings it will run. If you have installed a font in your machine and used the same font in your application then while running the application in client's machine the font will not be the same you have used. To make that, we need to embed the font in our Silverlight application.
To begin with, we will add a font to our Silverlight application. Create a folder named "Assets" and keep the font file (with extension *.ttf) inside it.
Now set the Build action to BlendEmbeddedFont.
Now go ahead and add a TextBlock into your application.
<TextBlock Height="40" FontSize="32" Width="Auto" HorizontalAlignment="Center" Text="This is an Embedded Font" />
To use the font you need to use the font in the following format.
Fonts.zip#FontName
<TextBlock Height="40" FontSize="32" Width="Auto" HorizontalAlignment="Center" Text="This is an Embedded Font" FontFamily="Assets/Fonts.zip#AajaxSurrealFreak" />
Now run your application and you will find that the font is embedded to the Application.
You can do the same in Expression Blend also.
Open the application in Blend 3. Select the TextBlock and choose the Font. Usually when you have a resource added to the Solution the Font is available in the fonts dropdown box.
Then Check the box named Embed.
Now your Font is a part of your Silverlight Application executables.
That's it. It's so easy to make the font embedding in your application.
Enjoy Coding.