Bugzilla – Bug 591702
PrivateFontCollection does not work
Last modified: 2011-05-23 15:30:25 UTC
Description of Problem: System.Drawing.Text.PrivateFontCollection is class which allows you to use own, custom fonts in TTF and sometimes in OTF formats. The problem is that it loads font, but method System.Drawing.Graphics.DrawString does not use these fonts. Sample code: using System; using System.Drawing; using System.Drawing.Text; using System.Drawing.Imaging; namespace DrawingTest { class MainClass { public static void Main(string[] args) { Image img = Image.FromFile("background.bmp"); Graphics g = Graphics.FromImage(img); g.Clear(Color.White); PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile("myFontFamily.ttf"); FontFamily myFontFamily = pfc.Families[0]; Font myFont = new Font(myFontFamily, 10); SolidBrush myBrush = new SolidBrush(Color.Black); g.DrawString("test", myFont, myBrush, 3, 3); img.Save("/home/rutek/test.bmp", ImageFormat.Bmp); g.Dispose(); } } } Actual Results: Used font is default font like on Windows systems before Windows 2000 on .NET platform( http://msdn.microsoft.com/en-us/library/system.drawing.text.privatefontcollection.addfontfile.aspx ). Expected Results: Used font is font which I loaded. How often does this happen? Always Additional Information: This post on Q&A site may be useful: "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." This bug was reported some time ago, but it has been marked as resolved, because it used to crash which has been repaired, but result has not been repaired. P.S. Sorry for my English, I still learn.
Also occurs in 2.6.7. This bug is a high priority for me too.
For the record, the Mono team no longer maintains WinForms. It's in the hands of the community, now. Just saying so you don't wait for nothing. If something is high priority for you, your best bet is to fix it yourself and submit a patch.
PS: this is not WinForms though, but Sys Drawing... but I think it's in the same situation. I haven't seen much activity on it over the last few years. Feel free to ask the Mono team for confirmation.