question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing font exception on Ubuntu since 0.101.0

See original GitHub issue

Do you want to request a feature or report a bug?

  • Bug
  • Feature
  • Question

Did you test against the latest CI build?

  • Yes - tested with 0.101.999.3068
  • No

Version of ClosedXML

0.101.0

What is the current behavior?

With 0.101.0 our automated tests on Github Linux/Ubuntu runner throw at new XLWorkbook(stream).

Unhandled exception. System.ArgumentException: Unable to find font Calibri or fallback font Microsoft Sans Serif. Install missing fonts or specify a different fallback font through 'LoadOptions.DefaultGraphicEngine = new DefaultGraphicEngine("Fallback font name")'. Additional information is available at https://closedxml.readthedocs.io/en/latest/tips/missing-font.html page.
   at ClosedXML.Graphics.DefaultGraphicEngine.LoadFont(MetricId metricId)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at ClosedXML.Graphics.DefaultGraphicEngine.GetFont(MetricId metricId)
   at ClosedXML.Graphics.DefaultGraphicEngine.CalculateMaxDigitWidth(MetricId metricId)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at ClosedXML.Graphics.DefaultGraphicEngine.GetMaxDigitWidth(IXLFontBase fontBase, Double dpiX)
   at ClosedXML.Excel.XLWorkbook.CalculateColumnWidth(Double charWidth, IXLFont font, XLWorkbook workbook)
   at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet)
   at ClosedXML.Excel.XLWorkbook.LoadSheets(Stream stream)
   at ClosedXML.Excel.XLWorkbook.Load(Stream stream)
   at ClosedXML.Excel.XLWorkbook..ctor(Stream stream, LoadOptions loadOptions)
   at ClosedXML.Excel.XLWorkbook..ctor(Stream stream)
   at Program.<Main>$(String[] args) in /home/jur/linuxrepos/external/closedxmlbug/Program.cs:line 3

The information at the URL is helpful for finding a workaround. In our case it’s a dumb implementation of IXLGraphicEngine where we just return default in all methods. We are not using any AdjustToContent and are just using XLWorkbook to read cell contents.

I think this is a bug in ClosedXML. Some reasons:

  1. We are not doing any AdjustToContent and the exception already happens at new XLWorkbook(stream).
  2. From a ClosedXML library perspective this makes it harder for people to start out with this library on systems (like Ubuntu) that don’t have the mentioned Calibri or Microsoft Sans Serif.
  3. Didn’t happen with any release before 0.101.0 and the release notes didn’t say anything about a breaking change.

https://github.com/ClosedXML/ClosedXML/commit/b655dc7a7334c991635dc82efc47153a353a39ef seems to have introduced this.

What is the expected behavior or new feature?

I would expect new XLWorkbook(stream) to not require having installed any fonts.

Is this a regression from the previous version?

Reproducibility

Code to reproduce problem:

In standard Ubuntu installation with dotnet sdk installed. I’m using WSL locally. And our CI uses Github actions with ubuntu-latest runner.

> dotnet new console
> dotnet add package ClosedXML

Program.cs:

using ClosedXML.Excel;
using var stream = File.OpenRead("./hello.xlsx");
_ = new XLWorkbook(stream);

Issue Analytics

  • State:closed
  • Created 5 months ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
CodeCasterNLcommented, Apr 28, 2023

Encountering this as well on GitHub Actions. Repro:

  • Have a “template” file built in Excel
  • Have an integration test that wants to read the data from this file
  • Read it through using var workbook = new XLWorkbook(File.OpenRead(excelFilePath))
  • Encounter the stated exception because Excel’s default theme wants the Calibri font

Workaround:

  1. Wait for 0.102 (Expected release date: Start of June)
  2. Revert to 0.100.3
0reactions
nbarbettinicommented, Jun 2, 2023

Similar issue, and like @jr01 I don’t need to call AdjustToContent or do any saving at all. This workaround worked fine on v0.101.0 (Linux):

    /// <summary>
    /// Dummy implementation of <see cref="IXLGraphicEngine"/> to avoid any dependency on specific fonts.
    /// In our case we don't need font support at all, because we are only reading data from the file.
    /// See https://github.com/ClosedXML/ClosedXML/issues/2066
    /// </summary>
    public sealed class NoFontsXLGraphicEngine : IXLGraphicEngine
    {
        public double GetDescent(IXLFontBase font, double dpiY) => default;

        public GlyphBox GetGlyphBox(ReadOnlySpan<int> graphemeCluster, IXLFontBase font, Dpi dpi) => default;

        public double GetMaxDigitWidth(IXLFontBase font, double dpiX) => default;

        public XLPictureInfo GetPictureInfo(Stream imageStream, XLPictureFormat expectedFormat)
            => DefaultGraphicEngine.Instance.Value.GetPictureInfo(imageStream, expectedFormat);

        public double GetTextHeight(IXLFontBase font, double dpiY) => default;

        public double GetTextWidth(string text, IXLFontBase font, double dpiX) => default;
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing font — ClosedXML 0.102.0 documentation
Missing font . This page should help resolve the exception about a missing font: Unable to find font font name or fallback font...
Read more >
How do I fix fonts not rendering and missing letters?
I have a fresh installation of Ubuntu 14.10 on my laptop. It appears that letters are missing from files and folders, as well...
Read more >
Missing Linux fonts - ubuntu
I pressed the install and got an error - with no explanation. I tried to manually copy the ttf fonts in the folder...
Read more >
LibreOffice: Certain Bundled Fonts Are Missing in Ubuntu
Since Ubuntu does not packages this exact font LibreOffice has to substitute the font and moreover is hinting this only by showcasing the...
Read more >
Ubuntu is missing windows fonts?
Googled and found this is due to Ubuntu missing windows based fonts. All the posts I found on internet about this issue are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found