views:

331

answers:

2

When I call the PrivateFontCollection.AddFontFile method in Mono.net It always returns a standard font-family. This bug has already been reported on several websites, but as far as I know without a way to solve it. The bug itself isn't fixed in the Mono-libraries yet. Is there any workaround for it?

EDIT: As a reaction on henchman's answer I will post the code:

PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile("myFontFamily.ttf");
myFontFamily = pfc.Families[0x00];
Font myFont = new Font(myFontFamily,14.0f);

I know this code will work fine on the Microsoft.Net framework, but when executing on Mono, it just gives a standard font-family (I think it is Arial) with the name of myFontFamily.ttf

A: 

I could find nothing on google for such a bug.

Does the following how-to work for you? http://msdn.microsoft.com/en-us/library/y505zzfw.aspx

Otherwise, could you please give us the code?

Thanks in advance.

henchman
I'm afraid this page didn't solved the problem.
CommuSoft
Your code works for me... does your font have a "regular" fontset included?msdn sais: "The AddFontFile is not supported on operating systems before Windows 2000. When using a private font on operating systems before Windows 2000, the default font, typically Microsoft Sans Serif, will be substituted." - perhaps a similar restriction exists for mono. Their docs are not too expressive ;-)
henchman
true but as I already said in the question, I'm using Mono under Linux/Ubuntu 9.10. I was wondering if their was any workaround to get the same results as under Microsoft.Net
CommuSoft
+1  A: 

Found this post from google. If it's any consolation, I'm experiencing the same issue with AddMemoryFont (works fine on Windows, mono gives me a generic font.) If it's any consolation, it looks like it's a problem with Mono, and not your code.

Digging through the source, System.Windows.Drawing.PrivateFontCollection is mostly just a wrapper around GDIPlus.GdipPrivateAddFontFile, which itself is a wrapper around fontconfig's FcConfigAppFontAddFile. The reason it doesn't appear to throw any errors is that GDIplus doesn't check for a return value from fontconfig, so it seems like fontconfig isn't able to read the font for whatever reason, but GDIplus doesn't know about it, so neither does PrivateFontCollection.

Hadley