1

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?

KateMak
  • 1,619
  • 6
  • 26
  • 42
  • is using the css @font-face rule an option? http://stackoverflow.com/questions/2436749/how-to-define-bold-italic-using-font-face – KHeaney Sep 03 '14 at 17:15
  • No, as I need to use the DrawString method on a Graphics object... – KateMak Sep 03 '14 at 17:43

1 Answers1

0

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);
Zer0
  • 7,191
  • 1
  • 20
  • 34
  • How can I get the "Light" version of the font? I have already tried the above approach, unfortunately, and cannot get the results I want. – KateMak Sep 03 '14 at 18:24
  • I'm not sure what font you're using, but if you look at common fonts installed on your system there are no separate "bold" or "italic" versions. If it's an issue with your font I just wouldn't use `PrivateFontCollection`. – Zer0 Sep 03 '14 at 18:28