Bug 591702 - PrivateFontCollection does not work
Summary: PrivateFontCollection does not work
Status: NEW
Alias: None
Product: Mono: Class Libraries
Classification: Mono
Component: Sys.Drawing. (show other bugs)
Version: 2.4.x
Hardware: x86 Ubuntu
: P5 - None : Major
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords: All_Languages, easy_fix
Depends on:
Blocks:
 
Reported: 2010-03-28 14:53 UTC by Lukasz Rutkowski
Modified: 2011-05-23 15:30 UTC (History)
2 users (show)

See Also:
Found By: Development
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lukasz Rutkowski 2010-03-28 14:53:23 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.
Comment 1 Campbell Wild 2011-05-17 14:05:58 UTC
Also occurs in 2.6.7.  This bug is a high priority for me too.
Comment 2 Thomas Goldstein 2011-05-20 19:02:32 UTC
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.
Comment 3 Thomas Goldstein 2011-05-23 15:30:25 UTC
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.