2

I've seen a handful of posts around the internet from 4-5 years ago (one from StackOverflow, seen here) but no solutions, nothing in changelogs on the GitHub repo for Mono, and no other mention of this. We have code that runs fine on Windows under the .Net Framework, but doesn't work correctly on Ubuntu 14.04.1 under Mono 3.2.8.

I've compiled just a simple console application illustrating the problem. If we use either AddFontFile() or AddMemoryFont() to load TTF data into a PrivateFontCollection, we can instantiate Font objects all day long that return the correct Name, but when trying to use that Font object in something like Graphics.MeasureString() or Graphics.DrawString() or Graphics.MeasureCharacterRanges(), it appears that the Font has fallen back to the Ubuntu system default font of "DejaVu Sans".

Code illustrating the issue is here:

        Dim pfc As New System.Drawing.Text.PrivateFontCollection

    pfc.AddFontFile("Open Sans Condensed Bold.ttf")

    Using f As New System.Drawing.Font(pfc.Families(0), 16)

        Using img As New System.Drawing.Bitmap(100, 500)

            Using g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(img)

                g.Clear(Drawing.Color.White)

                g.DrawString(f.Name, f, Drawing.Brushes.Black, 0, 0)

            End Using

            img.Save("testfont.png", System.Drawing.Imaging.ImageFormat.Png)

        End Using
    End Using

Is there a workaround available for this other than installing the fonts on the system the code is running on (that works by the way, even if executing the code above and not instantiating the Font by name, which leads me to believe that the problem may actually lie in libgdiplus since it uses fontconfig).

Has anyone else encountered this before? Doesn't matter what TrueType file I try, this will not work without the font being installed on the system.

Community
  • 1
  • 1
Matt
  • 285
  • 3
  • 12
  • For the one program that I needed it, i just installed the fonts... As far as I understand, that code would be a Community fix as it has never worked on linux and it is 'related' to WinForms and there are open bugs on it that go back to the Novell days. If you do a deep dive on it and fix it, create a pull-request for it ;-) – SushiHangover Sep 05 '15 at 05:18
  • I'm seeing the same issue on my Mac with OSX Yosemite 10.10.5 using Mono / .Net 4.5 (it works with Mono on windows), very frustrating and I don't see any workaround. – tzachs Oct 02 '15 at 04:07

0 Answers0