Workaround for the Mono PrivateFontCollection.AddFontFile bug
Asked Answered
F

1

11

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

Ferren answered 21/2, 2010 at 23:15 Comment(3)
Have you filed a bug in Mono's bugzilla? That's the only way for the team to know that there's a bug to fix in a first place.Violoncellist
The bug was already reported by someone else in November on bugzilla.ximian.com/show_bug.cgi?id=77498Ferren
This bug is marked as RESOLVED, and it was about a crash. Now the crash is fixed, but the behavior is still wrong. Please file a new bug with the appropriate expected behavior. Thanks!Violoncellist
T
2

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.

Taub answered 13/3, 2010 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.