`Console.Error` gets clogged up when accessing Fonts
RenderMichael opened this issue · 2 comments
Whenever I try to use a font, Console.Error
gets filled up with irrelevant error messages about fonts failing to load. This is because whenever the font resolver is accessed, all supported fonts are loaded and, when some of them fail, they log to error
PdfSharpCore/PdfSharpCore/Utils/FontResolver.cs
Lines 115 to 130 in 2d31ef5
This is unfortunate, as it clogs up Console.Error for me. I know PdfSharpCore isn't necessarily one-for-one, but PdfSharp for framework doesn't do this and this is the only thing hampering our migration. Is there anything that can be done?
Note this only happens on windows for me, not Ubuntu
The following is a test to check for this behavior (note fonts should not be accessed before this test otherwise it doesn't work)
[Fact]
public void LoadingFontsDoesNotLogToError()
{
var errorStream = new MemoryStream();
var errorWriter = new StreamWriter(errorStream);
Console.SetError(errorWriter);
var font = new XFont("Arial", 20, XFontStyle.BoldItalic);
errorWriter.Flush();
Assert.Empty(errorStream.ToArray());
}
For reference, this is what error looks like for me on Windows
System.IO.EndOfStreamException: End of stream reached with 27424 byte left to read.
at SixLabors.Fonts.BigEndianBinaryReader.ReadInternal(Byte[] data, Int32 size)
at SixLabors.Fonts.BigEndianBinaryReader.ReadString(Int32 bytesToRead, Encoding encoding)
at SixLabors.Fonts.Utilities.StringLoader.LoadValue(BigEndianBinaryReader reader)
at SixLabors.Fonts.Tables.General.Name.NameTable.Load(BigEndianBinaryReader reader)
at SixLabors.Fonts.Tables.General.Name.NameTable.Load(FontReader fontReader)
at SixLabors.Fonts.Tables.TableLoader.Load[TTable](FontReader reader)
at SixLabors.Fonts.FontReader.TryGetTable[TTableType]()
at SixLabors.Fonts.FontReader.GetTable[TTableType]()
at SixLabors.Fonts.FontDescription.LoadDescription(FontReader reader)
at SixLabors.Fonts.FontDescription.LoadDescription(String path)
at PdfSharpCore.Utils.FontResolver.FontFileInfo.Load(String path)
at PdfSharpCore.Utils.FontResolver.SetupFontsFiles(String[] sSupportedFonts)
System.IO.EndOfStreamException: End of stream reached with 27424 byte left to read.
at SixLabors.Fonts.BigEndianBinaryReader.ReadInternal(Byte[] data, Int32 size)
at SixLabors.Fonts.BigEndianBinaryReader.ReadString(Int32 bytesToRead, Encoding encoding)
at SixLabors.Fonts.Utilities.StringLoader.LoadValue(BigEndianBinaryReader reader)
at SixLabors.Fonts.Tables.General.Name.NameTable.Load(BigEndianBinaryReader reader)
at SixLabors.Fonts.Tables.General.Name.NameTable.Load(FontReader fontReader)
at SixLabors.Fonts.Tables.TableLoader.Load[TTable](FontReader reader)
at SixLabors.Fonts.FontReader.TryGetTable[TTableType]()
at SixLabors.Fonts.FontReader.GetTable[TTableType]()
at SixLabors.Fonts.FontDescription.LoadDescription(FontReader reader)
at SixLabors.Fonts.FontDescription.LoadDescription(String path)
at PdfSharpCore.Utils.FontResolver.FontFileInfo.Load(String path)
at PdfSharpCore.Utils.FontResolver.SetupFontsFiles(String[] sSupportedFonts)
System.IO.EndOfStreamException: End of stream reached with 27424 byte left to read.
at SixLabors.Fonts.BigEndianBinaryReader.ReadInternal(Byte[] data, Int32 size)
at SixLabors.Fonts.BigEndianBinaryReader.ReadString(Int32 bytesToRead, Encoding encoding)
at SixLabors.Fonts.Utilities.StringLoader.LoadValue(BigEndianBinaryReader reader)
at SixLabors.Fonts.Tables.General.Name.NameTable.Load(BigEndianBinaryReader reader)
at SixLabors.Fonts.Tables.General.Name.NameTable.Load(FontReader fontReader)
at SixLabors.Fonts.Tables.TableLoader.Load[TTable](FontReader reader)
at SixLabors.Fonts.FontReader.TryGetTable[TTableType]()
at SixLabors.Fonts.FontReader.GetTable[TTableType]()
at SixLabors.Fonts.FontDescription.LoadDescription(FontReader reader)
at SixLabors.Fonts.FontDescription.LoadDescription(String path)
at PdfSharpCore.Utils.FontResolver.FontFileInfo.Load(String path)
at PdfSharpCore.Utils.FontResolver.SetupFontsFiles(String[] sSupportedFonts)
System.IO.EndOfStreamException: End of stream reached with 27424 byte left to read.
at SixLabors.Fonts.BigEndianBinaryReader.ReadInternal(Byte[] data, Int32 size)
at SixLabors.Fonts.BigEndianBinaryReader.ReadString(Int32 bytesToRead, Encoding encoding)
at SixLabors.Fonts.Utilities.StringLoader.LoadValue(BigEndianBinaryReader reader)
at SixLabors.Fonts.Tables.General.Name.NameTable.Load(BigEndianBinaryReader reader)
at SixLabors.Fonts.Tables.General.Name.NameTable.Load(FontReader fontReader)
at SixLabors.Fonts.Tables.TableLoader.Load[TTable](FontReader reader)
at SixLabors.Fonts.FontReader.TryGetTable[TTableType]()
at SixLabors.Fonts.FontReader.GetTable[TTableType]()
at SixLabors.Fonts.FontDescription.LoadDescription(FontReader reader)
at SixLabors.Fonts.FontDescription.LoadDescription(String path)
at PdfSharpCore.Utils.FontResolver.FontFileInfo.Load(String path)
at PdfSharpCore.Utils.FontResolver.SetupFontsFiles(String[] sSupportedFonts)
I can submit a PR with a fix if we come to a conclusion about one.