Table of Contents

Class SkiaVectorRenderer

Namespace
PdfEngine.Vector.Skia
Assembly
PdfEngine.Vector.Skia.dll

Portable Skia renderer for the vector display list: a CPU raster backend with no platform dependency beyond SkiaSharp's native library, for hosts without Direct2D (the web viewer on WebAssembly, Android). It replays the display list with the semantics of the Direct2D backend (Replayer.cs there): hairlines one device pixel wide, embedded font programs loaded from memory, JPEG data decoded by Skia's codec, groups composited offscreen, night mode as the inverted day page, and fallback regions drawn from the provider's pixels last.

public sealed class SkiaVectorRenderer : IPdfVectorRenderer, IDisposable
Inheritance
SkiaVectorRenderer
Implements
Inherited Members

Remarks

Thread-safe: renders on one instance are serialized. Raster output is the output size itself (no GPU texture limit), so there is no tiling. One render is at most MaxRenderPixelCount pixels, as in the Direct2D and WPF backends: a larger page or region, or a buffer the process cannot allocate, is refused with a PdfResourceLimitException (LimitName "MaxRenderPixelCount").

Constructors

SkiaVectorRenderer(long, SkiaFontSource?, PdfSecurityLimits?)

Creates a renderer. One instance can render many pages; keep it for the life of the document view and dispose it at the end.

public SkiaVectorRenderer(long imageCacheBytes = 268435456, SkiaFontSource? fonts = null, PdfSecurityLimits? limits = null)

Parameters

imageCacheBytes long

Budget for decoded images kept across renders.

fonts SkiaFontSource

Where substitutes for non-embedded fonts come from; null uses SkiaFontSource (the installed fonts). A host without installed fonts (WebAssembly) passes its own.

limits PdfSecurityLimits

Image limits for the JPEG data the backend decodes itself (MaxImagePixels and MaxImagePixelsPerPage); null uses the defaults.

Properties

CachedImageBytes

Bytes of decoded images currently cached.

public long CachedImageBytes { get; }

Property Value

long

OutlineUnsupportedRegions

Outline fallback regions that no provider drew (strict vector mode). Off, a region shows what the engine draws of it by itself, with nothing laid over it.

public bool OutlineUnsupportedRegions { get; set; }

Property Value

bool

Methods

AnalyzeAsync(IPdfDisplayList, CancellationToken)

Regions this backend cannot draw faithfully (fonts it cannot load, glyphs a substitute lacks, undecodable images).

public Task<IReadOnlyList<PdfFallbackToken>> AnalyzeAsync(IPdfDisplayList displayList, CancellationToken cancellationToken = default)

Parameters

displayList IPdfDisplayList
cancellationToken CancellationToken

Returns

Task<IReadOnlyList<PdfFallbackToken>>

Dispose()

Releases the cached paths, images and typefaces.

public void Dispose()

OutputSize(IPdfDisplayList, RenderRequest)

Full-output pixel size of a request (page /Rotate plus viewer rotation).

public static (int Width, int Height) OutputSize(IPdfDisplayList list, RenderRequest request)

Parameters

list IPdfDisplayList
request RenderRequest

Returns

(int Width, int Height)

RenderAsync(IPdfDisplayList, RenderRequest, IPdfFallbackProvider?, SkiaPixelRegion?, bool, CancellationToken)

Renders the page, or only region of it (pixel window of the full output at the request's resolution). invertColors produces the night-mode page: the page is drawn as by day and every pixel inverted, so it is exactly the inverted day page (blend modes included), as the Direct2D backend's Invert effect makes it.

public Task<SkiaRenderResult> RenderAsync(IPdfDisplayList list, RenderRequest request, IPdfFallbackProvider? provider, SkiaPixelRegion? region, bool invertColors, CancellationToken ct)

Parameters

list IPdfDisplayList
request RenderRequest
provider IPdfFallbackProvider
region SkiaPixelRegion?
invertColors bool
ct CancellationToken

Returns

Task<SkiaRenderResult>

RenderDisplayListAsync(IPdfDisplayList, RenderRequest, IPdfFallbackProvider?, CancellationToken)

Draws displayList into a new BGRA pixel buffer.

public ValueTask<RenderedPage> RenderDisplayListAsync(IPdfDisplayList displayList, RenderRequest request, IPdfFallbackProvider? fallbackProvider = null, CancellationToken cancellationToken = default)

Parameters

displayList IPdfDisplayList

The page to draw, from GetPageDisplayListAsync(int, CancellationToken).

request RenderRequest

The resolution, output size and viewer rotation.

fallbackProvider IPdfFallbackProvider

Draws the regions this renderer cannot draw faithfully, or null to draw them by best effort.

cancellationToken CancellationToken

Cancels the render.

Returns

ValueTask<RenderedPage>

The pixels. Dispose the result to release its buffer.