Class SkiaVectorRenderer
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
imageCacheByteslongBudget for decoded images kept across renders.
fontsSkiaFontSourceWhere substitutes for non-embedded fonts come from; null uses SkiaFontSource (the installed fonts). A host without installed fonts (WebAssembly) passes its own.
limitsPdfSecurityLimitsImage 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
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
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
displayListIPdfDisplayListcancellationTokenCancellationToken
Returns
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
listIPdfDisplayListrequestRenderRequest
Returns
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
listIPdfDisplayListrequestRenderRequestproviderIPdfFallbackProviderregionSkiaPixelRegion?invertColorsboolctCancellationToken
Returns
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
displayListIPdfDisplayListThe page to draw, from GetPageDisplayListAsync(int, CancellationToken).
requestRenderRequestThe resolution, output size and viewer rotation.
fallbackProviderIPdfFallbackProviderDraws the regions this renderer cannot draw faithfully, or null to draw them by best effort.
cancellationTokenCancellationTokenCancels the render.
Returns
- ValueTask<RenderedPage>
The pixels. Dispose the result to release its buffer.