开发者

Can't load font using font file name

开发者 https://www.devze.com 2023-01-16 04:05 出处:网络
开发者_如何学JAVAThere 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
开发者_如何学JAVA

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消