Skip to main content
Home Forums Silverlight Programming Visual Studio & Silverlight Development Tools Embedding font
3 replies. Latest Post by WadeFlextronics on October 29, 2008.
(0)
RenukaPa...
Member
161 points
173 Posts
10-29-2008 8:05 AM |
Hi everyone
I have embeded the font by using following steps
1. I included the font in my application
2. I changed its build action to Resource
3. Then i included this font by using following statement fontfamily="fontfilename.ttf#fontname"
But it is not taking the font i had embedded instead it is displaying in default font.
Is anything else to do to embed the font in silvelright application
Thanks in advance
Renu
WadeFlex...
377 points
82 Posts
10-29-2008 8:44 AM |
If you are running in a dev environment then you will also need to set the Copy to Output folder on the font as well. This should solve the problem.
(Please mark as Answered if this helps!)
10-29-2008 8:52 AM |
hi,
I have set Copy to Output Directory property to Copy if newer. Still it is not working. My font file name is calibri.ttf and font name is Calibri. I have used as
FontFamily=calibri.ttf#Calibri. My question is any space should be provided before the font name that is "calibri.ttf# Calibri".
I may not know the difference between the calibri font and default font. so please tell me the default font in silverlight?.
Thanks
10-29-2008 9:40 AM |
From here: http://timheuer.com/blog/archive/2008/03/10/embedding-fonts-in-silverlight-2.aspx
For most, I think we'll want an easier implementation and something that feels a bit more natural. Well, in Silverlight 2, we now have it. Let's take a look at the above sample and how we could do that for Silverlight 2:
<TextBlock x:Name="Header" FontFamily="timheuer.ttf#Tim Heuer Normal" /> <TextBlock x:Name="ItemText" FontFamily="timheuer.ttf#Tim Heuer Normal" />
Okay, so what is happening here? What happened to the script? There is none (obviously). What is happening here is that Silverlight now does the lifting for you. Let's break this down a bit more.
First, the FontFamily is set to "timheuer.ttf" in this example, which is my handwriting font in TrueType format. This font is located next to the applications XAP file which is in ClientBin. It could be located anywhere in the same application domain and you could use an absolute URL here as well. For our purposes, we have a file on a web server.
When we set that in the FontFamily to a file, Silverlight essentially creates the downloader for us in an efficient manner. The font file is requested based on the URI provided and downloaded via a GET request. Once downloaded it parses out the second part (the "#") to look within that font file for the named font. So essentially the format is:
<file>#<named-font>
where # is the delimiter in this format. That's it, you are done. No script needed. If you choose to package several font assets within your application you can put them in a single archive file as well and the same syntax would apply:
<TextBlock x:Name="Header" FontFamily="timheuer.zip#Tim Heuer Normal" />
The same execution happens. Silverlight gets the archive file and then looks at the font file contents in the archive to find the first named font to use. The archive doesn't have to only have font files either...which is cool at times.