简体   繁体   中英

Use different weights of a custom font?

I have an asp.net application, and I am using a custom font, however I need to use both the bold version and the light version of the font. They are both from the same font family. I am adding them like this:

protected PrivateFontCollection pfc = new PrivateFontCollection();

pfc.AddFontFile(HttpContext.Current.Server.MapPath(@"~\Content\Fonts\Exo-Bold.ttf"));
pfc.AddFontFile(HttpContext.Current.Server.MapPath(@"~\Content\Fonts\Exo-Light.ttf"));

Font questionFont = new Font(pfc.Families[0], 32, FontStyle.Regular, GraphicsUnit.World);

Although I am adding two font files, there is only one item in the Families array of pfc, therefore everything gets printed bold no matter what FontStyle I specify. How can I use both of the files I have added, and how can I make some things bold and some things light?

There should be no need to add the same font twice with different styles. Most fonts support multiple styles. The below works fine when adding only something like Arial.ttf .

Font regularFont = new Font(pfc.Families[0], 32, FontStyle.Regular, GraphicsUnit.World);
Font boldFont = new Font(pfc.Families[0], 32, FontStyle.Bold, GraphicsUnit.World);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM