PdfSharpCore
PdfSharpCore copied to clipboard
Migrate ImageSharp → SkiaSharp for `ImageSource` + tests & documentation
Migrate ImageSharp → SkiaSharp for ImageSource + tests & documentation
Summary
This PR replaces the ImageSharp-based implementation with a new SkiaSharpImageSource for raster loading/manipulation and embedding images into PDFs. It also updates/extends the test suite (including SkiaSharp-specific tests) and adds clear build/test instructions with explicit prerequisites.
Why
- Licensing & distribution: SkiaSharp is MIT. ImageSharp uses the Six Labors Split License, which may require a commercial license in some scenarios. Moving to SkiaSharp reduces licensing friction while preserving feature richness.
- Cross-platform reliability: SkiaSharp provides mature bindings to Google’s Skia engine. Native asset packages are referenced to ensure stable behavior on Linux (CI and containers).
What changed
Library
- New image source: Added
SkiaSharpImageSourceand removedImageSharpImageSource. - Integration with
XImage: The defaultImageSource.ImageSourceImplnow usesSkiaSharpImageSource. - Package references: Removed
SixLabors.ImageSharp; addedSkiaSharpand the appropriate native assets package for Linux.
Tests
- New migration tests: Validate dimensions, alpha/transparent pixels,
SaveAsJpeg, PDF bitmap embedding paths, andFromFile/FromStream. - Additional coverage: Loading from raw byte arrays, JPEG quality affecting output size,
XImage.FromImageSource, and implicitImageSourceImplinitialization. - Rendering-diff tolerance: Introduced a small
DiffTolerance(instead of strict== 0) for assertions sensitive to backend rendering nuances, stabilizing tests across platforms. - Image merge sizing: Relaxed an overly strict size assertion after image consolidation.
Docs & scripts
- README: Added a “SkiaSharp Migration” section explaining rationale and impact.
- AGENTS.md: Build/test instructions (dotnet 8), non-interactive font installation notes, and prerequisites for image-based tests (e.g., Ghostscript, Microsoft TrueType fonts).
Backward compatibility
- Potentially breaking (internal): Projects that referenced
ImageSharpImageSourcedirectly should migrate toSkiaSharpImageSource. - Public surface: High-level APIs (
XImage.FromFile/FromStream) remain unchanged; the default image backend underneath is now SkiaSharp.
How to test
# (Ubuntu) prerequisites for image + font tests
sudo apt-get update
sudo apt-get install -y ghostscript ttf-mscorefonts-installer
fc-cache -f -v
# build & test
dotnet build PdfSharpCore.sln
dotnet test --framework net8.0 PdfSharpCore.Test/PdfSharpCore.Test.csproj
Checklist
- [x] Replace ImageSharp with SkiaSharp for the default image backend
- [x] Update package references (SkiaSharp + Linux native assets)
- [x] Add/adjust tests for SkiaSharp and stabilize rendering-sensitive assertions
- [x] Update README and add contributor build/test guidance