Skip to content

Add a SkiaSharp renderer - #291

Draft
eXpl0it3r wants to merge 2 commits into
masterfrom
feature/skiasharp
Draft

eXpl0it3r wants to merge 2 commits into
masterfrom
feature/skiasharp

Conversation

@eXpl0it3r

@eXpl0it3r eXpl0it3r commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This adds HtmlRenderer.SkiaSharp, a new adapter that renders HTML onto any SKCanvas, into an SKImage and into paginated PDFs, on Windows, Linux and macOS. It's the first adapter that isn't tied to Windows, and the PDF output doesn't need PdfSharp, so it could be a cross-platform successor for both the image and the PDF use cases.

The adapter itself:

  • Text is shaped per word with HarfBuzz, so kerning, ligatures and joined Arabic letters work, and right-to-left words read correctly
  • Characters the chosen font lacks fall back to an installed font that has them, e.g. CJK text in a Latin font
  • @font-face and HtmlRender.AddFontFamily for fonts that aren't installed, and Liberation fonts as replacements for Arial, Times New Roman and Courier New on Linux
  • HtmlRender.RenderAsync, MeasureAsync and RenderToImageAsync, the image size is limited to 4096 x 32768 without a max size, as Skia can't allocate anything much bigger
  • PdfGenerator.GeneratePdfAsync paginates through the fragmentation tree, uses the print media type, and turns links into PDF link annotations, internal anchors included
  • Pens thinner than 1px are drawn 1px wide, as GDI+ and CSS Values 4 §6 do, otherwise sub-pixel borders vanish

The core only gets one change, a MediaType per container, so the PDF generator can render with print while images keep screen, see the first commit.

For the tests, there are unit tests for the rendering, the text shaping and the PDF generation, plus a pixel comparison of every demo sample against baseline images per OS. Skia's anti-aliasing differs by a few pixels between CPUs, so up to 64 differing pixels per image are accepted. The Linux baselines come from the Ubuntu runner, which has no CJK font, so the Korean and Japanese names in the Languages sample are boxes there.

Known limitations, all documented in the package README:

  • A line that mixes text directions isn't reordered as a whole, only each word
  • SkiaSharp's PDF backend doesn't subset fonts, so a PDF embeds the complete font files, which gets big with CJK fallback fonts

Rendering in parallel isn't thread safe yet, but that's in the core and affects every adapter, the shared pen, brush and font caches aren't locked. That will be a separate PR.

How to test this PR?

CI should succeed, and the Windows jobs should upload HtmlRenderer.SkiaSharp in the NuGet artifacts. Additionally, check the generated PDFs in the PDF artifacts or run the quick start from the package README.

@eXpl0it3r
eXpl0it3r force-pushed the feature/skiasharp branch 2 times, most recently from 6c7a4be to 21bf38d Compare November 15, 2026 14:37
- Render to an SKCanvas or SKImage, shape text with HarfBuzz
- Generate paginated PDFs with SkiaSharp's PDF backend
- Compare the regression samples against per OS pixel baselines
- Pack the HtmlRenderer.SkiaSharp NuGet package in CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant