[Mono-bugs] [Bug 591702] New: PrivateFontCollection does not work

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Mar 28 10:53:25 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=591702

http://bugzilla.novell.com/show_bug.cgi?id=591702#c0


           Summary: PrivateFontCollection does not work
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.4.x
          Platform: x86
        OS/Version: Ubuntu
            Status: NEW
          Keywords: All_Languages, easy_fix
          Severity: Major
          Priority: P5 - None
         Component: Sys.Drawing.
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: rrutek at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Development
           Blocker: ---


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.

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list