Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded Font in WPF not working

Tags:

c#

wpf

fonts

I have a WPF application where I use icons from the font "Segoe UI Symbol". But when deploying to Windows 7 I realize the icons are missing because the font is updated in Windows 8.

I tried to embed font in WPF application as a resource following these instructions: http://msdn.microsoft.com/en-us/library/ms753303.aspx But it does not work.

Initially I had:

<TextBlock FontFamily="Segoe UI Symbol">

which works fine on Windows 8 computer. Then I added seguisym.ttf to directory "_Resources" and then use:

<TextBlock FontFamily="./_Resources/#Segoe UI Symbol">

This does not work on neither Windows 8 or Windows 7! I tried different settings for BuildAction: Resource, Embedded Resource and Content, but none of them work.

like image 650
Jakob Lithner Avatar asked Jan 11 '15 23:01

Jakob Lithner


2 Answers

I finally found a way to use the newer version of "Segoe UI Symbol" even when older version is installed (i.e. on Windows 7). This approach works also in ClickOnce installation and requires no bootstrapping.

I guess the problem is caused by a name conflict with a font already loaded in Windows. So I renamed the newer version to avoid the conflict. It works.

1) Download utility program Typograf from this link: http://www.neuber.com/typograph/
2) Open directory where you have a copy of your font file
3) Click on font in list
4) Click Properties button in bar
5) Click Rename button, specify a new name (I chose "SegoeDynamic") and select where to save the new file
6) Add the new font file to your Visual Studio project directory (my directory is "/_Resources")
7) Use relative path or root path as you wish when referencing the font dynamically

 <TextBlock FontFamily="../_Resources/#SegoeDynamic">
 <TextBlock FontFamily="pack://application:,,,/_Resources/#SegoeDynamic">

Please observe that "Segoe UI Symbol" is released in several versions where each version adds more symbols. I have discovered at least the following:

Windows 7: 5.01 ( 823kb)

Windows 8: 5.90 (1660kb)

Windows 8.1: 6.09 (1740kb)

like image 171
Jakob Lithner Avatar answered Sep 19 '22 12:09

Jakob Lithner


First of all thanks a lot to @Jakob Lithner and other contributors.

-> I'm testing my wpf application on a win 7 PC which didn't support some of my unicode characters. As suggested, I created a Resources>Fonts folder inside my c#-project and copied the font seguisym.ttf inside (added as a "resource"; "copy if newer").

FontFamily="pack://application:,,,/<NameOfMyC#ProjectInSolution>;component/Resources/Fonts/seguisym.ttf#Segoe UI Symbol"

The only change with respect to the solution of Mr. Linthner is that I didn't rename the font, and prepended the font-filename to "#Segoe UI Symbol"

Kind regards from Belgium!

like image 45
Pieter Depamelaere Avatar answered Sep 19 '22 12:09

Pieter Depamelaere