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.