Closed misterspeedy closed 1 year ago
Looks like there is currently no cross platform way to enumerate available fonts! Currently investigating whether there is a set of font names we can rely on normally existing on major linux distros.
What about to add a default font?
ClosedXML uses SixLabors.Fonts as default:
Graphic engine is responsible for extracting information about images and measuring size of a text in a workbook. The exception indicates that ClosedXML (more precisely SixLabors.Fonts that is used by the default engine) wasn’t enable to find a font that could be used to measure size of a text.
Calculating a correct size of a text rendered by a font is a nontrivial task and there is a dearth of maintained open source .NET font libraries. That is why ClosedXML depends on prerelease version of SixLabors.Fonts.
DefaultGraphicEngine tries to use a requested font (e.g. font of a cell) and if the requested font isn’t present on the machine, it will use fallback font (Microsoft Sans Serif). If not even fallback font is found, it throws the aforementioned exception.
@adelarsq Ah - thanks, you set me on the right track. It turns out the SixLabors lets you enumerate fonts so we can just take the first few results from that rather than having hardwired fonts. Please could you try out the Tutorial.dib
I've just pushed and see if it works on Linux? Many thanks!
@adelarsq Although I fixed the example where we enumerate font names, I see that autosizing also causes an exception - which I think is what you were originally getting at with this issue. I will work to fix that too.
(I've created an Ubuntu instance on VirtualBox so I can do some basic crossplat testing myself.)
Cool! I did take a look on the Tutorial.dib
but I didn't have time to do some tests. Are you thinking into configure a default font or take the first available?
(I've created an Ubuntu instance on VirtualBox so I can do some basic crossplat testing myself.)
Nice. I will create a Docker config, so some CI/CD tests can be made. What do you think?
Closing as fixed - we have a separate issue for the default font issue with sizing.
@misterspeedy Nice! Can I send the code example as a pull request on this repository within an examples directory?