tags:

views:

84

answers:

2

I need my WPF app to use a true-type font for a different language. I have the font located in a folder called 'fonts' inside the project. The font i'm using is available for free download here

Since the font is installed in my system i first tried

 FontFamily="FMBasuru"

I've read the post here and tried doing (this is the exact markup im using including font name)

<Window.Resources>
        <Style x:Key="SinhalaFont">
            <Setter Property="TextElement.FontFamily" Value="fonts/#FMBasuru"/>
        </Style>
    </Window.Resources>

...

 <TextBlock  Style="{DynamicResource SinhalaFont}">r</TextBlock>

...

I made sure that I'm using the correct font name instead of the font filename. What could have i got wrong? Please help.

+1  A: 

I tried your code with this

  <Setter Property="TextElement.FontFamily" Value="fonts/#Arial Narrow Bold"/>

and it worked successfully.

Have you marked your font as 'Resource' in the Build Action? If you haven't, do that now and try your code again.

Mamta Dalal
Yes build action's set to 'Resource'. This font is installed in my system. But even FontFamily="SpecialFont" doesn't work.
smkngspcmn
The fonts directory containing the font is placed in the root of your WPF application, I hope. I couldnt reproduce your error, its working fine here. Can you paste the entire markup here including how you have named the font?
Mamta Dalal
Yeah the fonts directory is application/fonts/... Let me reedit my question and post the entire mark up.
smkngspcmn
I checked the properties of the font and it says its embeddability is restricted. Could that be the reason for this issue? But you did mention that it worked in ASP.NET. Can you let me know how exactly you referred to it in ASP.NET?
Mamta Dalal
Through CSS actually. Just font-family="FMBasuru";. I also just tried using it in a WinForms app. That works too. Then i gave a shot at creating a Drawing.Font object for that font as done in WinForms and converting it to type Media.Font. It converts great but still doesn't show up!
smkngspcmn
Ok this is crazy. I just had a look at the collection returned from System.Windows.Media.Fonts.SystemFontFamilies. That has the font but with an 'x' at the end > 'FMBasuru x'. I used that and it works great. I thought what i need to use is the type face name like i've done in asp.net and winforms. Was i wrong? Sorry if i wasted all your time on something stupid!
smkngspcmn
Not a waste of time at all. We got to learn something new! Upvoted your question in fact.
Mamta Dalal
Yeah, FMBasurux is a Sinhala font, it always requires the 'x' at the end.
Otaku
+1  A: 

Updated: Create a folder name Fonts and copy the font which you want and change the BuildAction to Resource

  <Window.Resources>
    <FontFamily x:Key="test" >/Fonts/#Pirulen</FontFamily>
</Window.Resources>
<Grid>
    <TextBlock FontSize="25" HorizontalAlignment="Center" 
               FontFamily="{StaticResource test}">Kishore Kumar</TextBlock>
</Grid>

just refer this document

http://stackoverflow.com/questions/358501/wpf-add-custom-font

Kishore Kumar
Of course i read that! The link i've given in my question is to that page itself.
smkngspcmn
just check my updated anser....
Kishore Kumar
Thanks for that. But turns out it was something wrong with the way specified the font name.
smkngspcmn