Page view counter

Silverlight Tips of the Day - Blog by Mike Snow

Game Programming with Silverlight

Silverlight Tip of the Day #46 – Font Support in Silverlight

Default Fonts

By Default, Silverlight supports the following local fonts (as shown rendered in Silverlight):

image 

You can also choose from a long list of East Asian fonts if they are available on your local computer:

  1. Batang
  2. BatangChe
  3. DFKai-SB
  4. Dotum
  5. DutumChe
  6. FangSong
  7. GulimChe
  8. Gungsuh
  9. GungsuhChe
  10. KaiTi
  11. Malgun Gothic
  12. Meiryo
  13. Microsoft JhengHei
  14. Microsoft YaHei
  15. MingLiU
  16. MingLiu_HKSCS
  17. MingLiu_HKSCS-ExtB
  18. MingLiu-ExtB
  19. MS Gothic
  20. MS Mincho
  21. MS PGothic
  22. MS PMincho
  23. MS UI Gothic
  24. NSimSun
  25. NSimSun-18030
  26. PMingLiU
  27. PMingLiu-ExtB
  28. SimHei
  29. SimSun
  30. SimSun-18030
  31. SimSun-ExtB

Custom Fonts

In addition to the default fonts users can use their own custom made or purchased fonts. Make certain you have the legal rights to using these fonts in your application.

The steps you need to take to import and use a custom font are:

  1. Right click on your Silverlight application project folder in the Solution Explorer, choose “Add->New Item…”
  2. Browse to your font, select it and click the OK button.
  3. Select the font, in the property grid set the Build Action = “Resource” and the “Copy to Output Directory” = “Copy if newer”:

    image
  4. Now, in your XAML, in order to reference the font in an element like a TextBlock use the following syntax in the attribute FontFamily as highlighted in yellow below - FontFamily=”[FontFileName]#[FontFriendlyName]”

    Example: <TextBlock Text="Hi" FontFamily="Century.ttf#Century"></TextBlock>
  5. To get the exact name of the font just double click on the font in the solution explorer to open the font viewer:

image

Supported Types.

The following types of user added fonts are supported: TTF, ODTTF and OTF. Silverlight will not recognize other font types such as FON and TTC that are added by a user. If, however, the system has these fonts already installed they will be recognized.

Additional Notes

You may have noticed from Tip of the Day #45 that Silverlight provides an option for text called FontStretch that allows you to stretch the font. However, when applied to normal fonts like “Arial”, “Verdana”, “Times New Roman”, etc you might notice that nothing happens. This is because Silverlight does not do any stretch emulation. This option must be applied to fonts that specifically support it such as Adobe Open type (OTF) fonts.

Thank you,
--Mike Snow

 Subscribe in a reader

Comments

Visual Web Developer Team Blog said:

Silverlight Tip of the Day #46 Title: Font Support in Silverlight Silverlight Tip of the Day #45: Title:

# September 25, 2008 1:55 PM

Microsoft Weblogs said:

Default Fonts By Default, Silverlight supports the following local fonts (as shown rendered in Silverlight

# September 25, 2008 2:41 PM

heuertk said:

Actually the supported method is using 'Resource' as the build action.  See: silverlight.net/.../learnvideo.aspx for a walk through.

# September 25, 2008 2:51 PM

mike.snow said:

Thanks for catch Tim, fixed!

# September 25, 2008 3:25 PM

jukia7 said:

I noticed that when including two fonts in a project, it can increase the size of the .xap if each font is sized 100kb. Is it possible to load a font as an external resource so the font is not compiled in the .xap? (in the same manner as you'd load an large jpeg/png from an external website)

# September 25, 2008 4:54 PM

Community Blogs said:

Tim Heuer on Isolated Storage, Dan Wahlin Animating Clipping Paths, Mike Snow on Fonts and TextBlocks

# September 25, 2008 6:45 PM

2008 September 25 - Links for today « My (almost) Daily Links said:

Pingback from  2008 September 25 - Links for today &laquo; My (almost) Daily Links

# September 26, 2008 4:58 AM

Dew Drop – September 26, 2008 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop &ndash; September 26, 2008 | Alvin Ashcraft's Morning Dew

# September 26, 2008 8:38 AM

Silverlight news for September 29, 2008 said:

Pingback from  Silverlight news for September 29, 2008

# September 29, 2008 11:58 AM

Silverlight Tips of the Day - Blog by Mike Snow said:

The purpose of this post is to create an outline summary all the blogs from my Silverlight tips of the

# January 2, 2009 5:57 PM

o UAU nosso de cada dia said:

essa lista eu copiei desse blog bárbaro (acompanhe por RSS você também): uma lista de dicas super úteis

# January 3, 2009 6:25 AM

Ouabache said:

Okay, very nice, but not good enough for my application.

How about being able to list the fonts on the client's machine and chosing one of them dynamically?

In other words, Peter load's my Silverlight application over the Web and I let him chose the font on his machine, not an embedded one.

# February 28, 2009 11:07 PM

Kevin Yang said:

about the "font name" thing,actually this is not quite right for those non-english fonts in non-english os.

for example, in non-english os, those non-english fonts,like 'Simsun' will show as '宋体'(Chinese Name), not 'Simsun'.But in blend, when you explictly embed the font to your app, blend will referrence fonts as '宋体' not 'Simsun',which will result in 'font missing' problem.

check www.54kevinyang.cn/.../%E8%A7%A3%E5%86%B3silverlight%E5%BC%95%E7%94%A8%E4%B8%AD%E6%96%87%E5%AD%97%E4%BD%93%E7%9A%84%E9%97%AE%E9%A2%98.html

# September 9, 2009 4:19 AM