I'm trying to create an image by drawing a text using a TTF font. I'm using .net core 2.1.500 on MacOS, and have mono-libgdiplus v5.6 (installed via brew).
The TTF file is Neo Sans Medium and this is my code (I tried with different TTF fonts, always with the same result)
using (var bmp = new Bitmap(1024, 512))
{
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
var rectf = new RectangleF(0, 40, 1024, 90);
// If I specify a font that it doesn't know, it defaults to Verdana
var defaultFont = new Font("DefaultFont", 55);
Console.WriteLine($"defaultFont: {defaultFont.Name}"); // => defaultFont: Verdana
g.DrawString("Text with default", defaultFont, Brushes.Black, rectf);
var privateFontCollection = new PrivateFontCollection();
privateFontCollection.AddFontFile("/path/to/Neo_Sans_Medium.ttf");
var fontFamilies = privateFontCollection.Families;
var family = fontFamilies[0];
var familyHasRegular = family.IsStyleAvailable(FontStyle.Regular);
Console.WriteLine($"familyHasRegular: {familyHasRegular}"); // => familyHasRegular: true
var textFont = new Font(family, 55);
Console.WriteLine($"textFont: {textFont.Name}"); // => textFont: Neo Sans
var rectText = new RectangleF(0, 140, 1024 - 50 - 50, 1024 - 50 - 10);
g.DrawString("Text with loaded font", textFont, Brushes.Black, rectText);
g.Flush();
g.Save();
bmp.Save("test.png", ImageFormat.Png);
}
Since it printed textFont: Neo Sans, it seems to me that it was properly loaded (otherwise, it would have defaulted to Verdana).
However, the output I'm getting is this one:

Am I missing something?
