Use different weights of a custom font?

402 views Asked by At

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?

1

There are 1 answers

2
Zer0 On

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);