This repository contains a refactored version of ClosedXML that introduces a pluggable graphics engine architecture. This change removes the hard dependency on SixLabors.Fonts from the core library, making it lightweight and more flexible for different environments.
- Pluggable Architecture: The
IXLGraphicEngineinterface has been extracted, allowing different implementations for text measurement and image handling. - Dependency Removal: The core
ClosedXMLpackage no longer depends onSixLabors.Fonts. - Default Implementation: An embedded
ApproximateGraphicEngineis used by default. It uses precomputed metrics for the Carlito font and requires no external dependencies. - New Packages:
ClosedXML.Graphic.SixLabors: The original implementation usingSixLabors.Fonts.ClosedXML.Graphic.Skia: An implementation usingSkiaSharp.ClosedXML.Graphic.GDI: An implementation usingSystem.Drawing.Common(GDI+), utilizing installed system fonts.
By default, ClosedXML uses the ApproximateGraphicEngine. This works out-of-the-box without any additional configuration or packages.
using var workbook = new XLWorkbook();
// Uses ApproximateGraphicEngineTo use the original accurate text measurement:
- Install the
ClosedXML.Graphic.SixLaborspackage. - Configure the engine at startup or per-workbook.
// Global configuration
LoadOptions.DefaultGraphicEngine = new SixLaborsGraphicEngine();
// Or per-workbook
var options = new LoadOptions
{
GraphicEngine = new SixLaborsGraphicEngine()
};
using var workbook = new XLWorkbook(options);To use SkiaSharp for rendering metrics:
- Install the
ClosedXML.Graphic.Skiapackage. - Configure the engine.
LoadOptions.DefaultGraphicEngine = new SkiaGraphicEngine();To use installed system fonts on Windows (or configured GDI+ environments):
- Install the
ClosedXML.Graphic.GDIpackage. - Configure the engine.
LoadOptions.DefaultGraphicEngine = new GdiGraphicEngine();Same as ClosedXML (MIT).