PeachDrawing

PeachDrawing

RasterRenderContext Class

A RenderContext for drawing directly onto a RasterCanvas canvas with no HTML, CSS, layout, or PDF document involved. CreateCanvas(int, int, double) is the entry point:

using var ctx = new RasterRenderContext();
using var canvas = ctx.CreateCanvas(width: 800, height: 600);
canvas.DrawRectangle(ctx.GetSolidBrush(PaintColor.FromArgb(255, 30, 144, 255)), 50, 50, 200, 100);
canvas.Save(stream, "png", new PngEncoderOptions());
public sealed class RasterRenderContext : PeachDrawing.Core.RenderContext

Inheritance System.Object → RenderContext → RasterRenderContext

Remarks

Font creation goes through TypefaceFont and image decoding through DecodedImage - both PeachDrawing.Core/PeachDrawing’s own types, no PDF backend involved anywhere in the chain.

Constructors  
RasterRenderContext() Creates a render context with every font installed on the machine already registered by name.
Properties  
LayoutUnitsPerPoint The factor between the layout units font sizes are requested in and the points the font behind them is built at (points = size / LayoutUnitsPerPoint). It is part of a cached font’s identity: the same requested size under a different scale is a different physical font, so the font handler keys every font cache by it. 1 for an adapter whose layout unit is the point.
PixelsPerPoint Layout units per point, as LayoutUnitsPerPoint reports it: 1 (the default) means a layout unit is a point, which a canvas from CreateCanvas(int, int, double) then draws as one device pixel. A document laid out against this context at 96.0 / 72.0 has CSS pixels as its layout unit, so a canvas from CreateCanvas(int, int, double) shows it at one CSS pixel per device pixel with no transform in between, and the engine’s snapping of boxes and borders to whole CSS pixels lands on whole device pixels. Set it before the document is loaded.
ResourceLoader Answers a document’s requests for what it refers to (an image, a style sheet, a font) by address, or null (the default) to load nothing: a surface has no resource loading of its own.
Methods  
AddFont(Stream, string) Registers a font directly under fontFamilyName, bypassing CSS @font-face entirely.
CreateCanvas(int, int, double) Creates a standalone RasterCanvas canvas of exactly widthPx by heightPx device pixels. This canvas’s own coordinate convention is plain: one user-space unit is one device pixel, regardless of dpi - a Rect(0, 0, 100, 50) and a font size of 24 both mean exactly that many pixels. dpi is accepted for forward compatibility (a future encoder that tags physical resolution on save) but does not otherwise affect drawing today.
GetCssMediaType(IEnumerable<string>) The CSS media type (e.g. "print", "screen") this render context evaluates media queries against, chosen from mediaTypesAvailable.
GetResourceStream(Uri) Gets the given resource using the provided network loader, or null by default (a render context with no resource-loading concept, e.g. a standalone raster surface, simply never resolves a URL-based resource - AddFontFamilyFromUrl(string, string, string, Uri, FontFaceDescriptors, IReadOnlyList<RuneInterval>) then reports the load as failed rather than throwing). A backend that loads resources overrides this.