kumar
kumar

Reputation: 209

Can't load font using font file name

There is font file in Windows folder (Font name is Lucida Sans). I try to load that font using following code but I can't create the font object

        PrivateFontCollection c = new PrivateFontCollection();
        c.AddFontFile("c:\\windows\\LSANSDI.TTF");
        FontFamily fa = c.Families[0]; //This line succeeds
        Font fn = new Font(fa, 10);  //I get Exception here and it says that it does not support Regular style

Even if u check all styles using fa.IsStyleAvailable function, I get no style available. What is the use of creating such ttf file which cannot be loaded. How can I use that font? But I can see that font has all styles available when I use in MS Word Can anyone provide the solution?

Upvotes: 0

Views: 1533

Answers (1)

Bargaintuan
Bargaintuan

Reputation: 31

My guess is that the font is bold AND italic, which means you need to check for (FontStyle.Bold | FontStyle.Italic) being available, and create the new Font accordingly.

Upvotes: 3

Related Questions