ArgumentException trying to create a Font that I don't understand

N

NeilL

I have a C# application that does something simple like the following

Font newFont = new Font( "Albertus Extra Bold (W1)", 8.5f, FontStyle.Regular);

that throws the following exception:

System.ArgumentException: Font 'Albertus Extra Bold (W1)' does not support
style 'Regular'.
at System.Drawing.Font.CreateNativeFont()
at System.Drawing.Font.Initialize(FontFamily family, Single emSize,
FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font.Initialize(String familyName, Single emSize,
FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font..ctor(String familyName, Single emSize, FontStyle
style)
at TastingMaster.TastingInvitationsForm.GetCurrentFontInfo() in
D:\TastingMaster\Source\TastingMaster\TastingMaster\Tastings\TastingInvitationsForm.cs:line 890

I've looked around and all the posts I've seen seem to say that the font is
corrupted. Since I'm able to use the same font and (I think) with the same
settings it would appear as though the font is not corrupted.

Does anyone have a hint as to what might be the issue here. As a workaround,
is there a way, given the font name, to determine if a particular style is
supported or not?

Thanks
 
J

Jeff Johnson

System.ArgumentException: Font 'Albertus Extra Bold (W1)' does not support
style 'Regular'.
I've looked around and all the posts I've seen seem to say that the font
is
corrupted. Since I'm able to use the same font and (I think) with the same
settings it would appear as though the font is not corrupted.
Does anyone have a hint as to what might be the issue here.

I think the font itself has a hint for you, considering that its name has
the word "bold" in it. That's a pretty big clue that this particular font is
not available in a normal weight.

I don't have "Albertus Extra Bold (W1)" on my system, but I do have
"'Albertus Extra Bold (TrueType)". It's bold only.
As a workaround,
is there a way, given the font name, to determine if a particular style is
supported or not?

The FontFamily class has an IsStyleAvailable() method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top