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?
.NET 5 Console App Fonts
Re: .NET 5 Console App Fonts
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
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