.NET 5 Console App Fonts

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Brian Kohrs
Newbie
Newbie
Posts: 3
Joined: Fri Jul 12, 2019 12:00 am

.NET 5 Console App Fonts

Post by Brian Kohrs » Fri Jul 09, 2021 7:39 pm

If you have a .NET 5 console application and attempt to set the font name to a non-default value, the application fails with the following exception.

Unhandled exception. SixLabors.Fonts.Exceptions.FontFamilyNotFoundException: Tahoma could not be found
at SixLabors.Fonts.FontCollection.FindInternal(String fontFamily, CultureInfo culture)
at Steema.TeeChart.Drawing.ChartFont.vur()
at Steema.TeeChart.Drawing.ChartFont.get_DrawingFont()
at Steema.TeeChart.Drawing.Graphics3DImageSharp.MeasureString(IChartFont f, String text)
at Steema.TeeChart.Drawing.Graphics3DBase.TextWidth(String text)
at Steema.TeeChart.Drawing.Graphics3DBase.get_FontSpace()
at Steema.TeeChart.Legend.Paint(IGraphics3D g, Rectangle rect, Boolean doDraw, Boolean doCalc)
at Steema.TeeChart.Chart.DoDrawLegend(Rectangle& tmp, Boolean doDraw, Boolean doCalc)
at Steema.TeeChart.Chart.DrawTitlesAndLegend(Rectangle& tmp, Boolean BeforeSeries)
at Steema.TeeChart.Chart.InternalDraw(Boolean noTools)
at Steema.TeeChart.TChart.Draw(IImageProcessingContext g, Rectangle rect)
at Steema.TeeChart.TChart.spm.pag(IImageProcessingContext s)
at SixLabors.ImageSharp.Processing.ProcessingExtensions.Mutate[TPixel](Image`1 source, Configuration configuration, Action`1 operation)
at Steema.TeeChart.TChart.Bitmap(Int32 width, Int32 height)
at Steema.TeeChart.Export.ImageExportFormat.Save(Stream stream)
at Steema.TeeChart.Export.ImageExportFormat.Save(String fileName)

Here is the code I used to reproduce the issue.

var chart = new TChart();
chart.Legend.Font.Name = "Tahoma";
var area = new Area();
area.Add(1, 2);
area.Add(2, 3);
area.Add(3, 6);
chart.Series.Add(area);
chart.Export.Image.PNG.Width = 800;
chart.Export.Image.PNG.Height = 600;
chart.Export.Image.PNG.Save("chart.png");

If I add this line, it works around the issue.

ChartFont.FontCollection.Install(@"C:\windows\fonts\Tahoma.ttf");

Is there another way to get the system fonts loaded other than iterating the file system and loading them like this?

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: .NET 5 Console App Fonts

Post by Marc » Mon Jul 12, 2021 2:13 pm

Hello,

Manually loading the font is the current best option when using SixLabors' Font with TeeChart.

Further reference: https://github.com/SixLabors/Fonts

Regards,
Marc
Steema Support

Post Reply