PeachDrawing.Core

PeachDrawing.Core

RenderContext Class

Platform adapter to bridge platform specific objects to HTML Renderer core library.
Core uses abstract renderer objects (RenderContext/RControl/REtc...) to access platform specific functionality, the concrete platforms implements those objects to provide concrete platform implementation. Those allowing the core library to be platform agnostic.

Platforms: WinForms, WPF, Metro, PDF renders, etc.
Objects: UI elements(Controls), Graphics(Render context), Colors, Brushes, Pens, Fonts, Images, Clipboard, etc.

public abstract class RenderContext

Inheritance System.Object → RenderContext

Remarks

It is best to have a singleton instance of this class for concrete implementation!
This is because it holds caches of default CssData, Images, Fonts and Brushes.

Properties  
BaseUri The document’s base URI resource loading resolves relative references against, or null when this adapter has none (the default - resource loading is entirely optional for a render context that doesn’t need it, e.g. one driving a standalone raster surface with no document/network concept at all). A backend that renders a document overrides this.
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.
MaxRasterPixels The most pixels one raster surface may have before its resolution is lowered to fit.
RasterAntiAliasing Whether the raster backend anti-aliases what it draws (see PdfGenerateConfig.RasterAntiAliasing).
RasterizationDpi The resolution, in pixels per inch of paper, the raster backend renders effects at (see PdfGenerateConfig.RasterizationDpi). Set per render by the owner of the adapter.
TextHinting How the raster backend fits glyph outlines to its pixel grid (see PdfGenerateConfig.TextHinting).
TextStemDarkening Whether hinted text of a font with CFF outlines has its stems thickened (see PdfGenerateConfig.TextStemDarkening).
Methods  
AddFontFamily(FontFamily) Adds a font family to be used.
AddFontFamilyFromUrl(string, string, string, RUri, FontFaceDescriptors, IReadOnlyList<RuneInterval>)  
AddFontFamilyMapping(string, string) Adds a font mapping from fromFamily to toFamily iff the fromFamily is not found.
When the fromFamily font is used in rendered html and is not found in existing fonts (installed or added) it will be replaced by toFamily.
AddLocalFontFamily(string, string, FontFaceDescriptors, IReadOnlyList<RuneInterval>) Registers a locally-installed font face under fontFamilyName, matching a CSS @font-face rule’s local() source.
ClearFontCache() Discards every font this context has resolved and cached so far.
CreateSvgGlyphPainter(Canvas) An ISvgGlyphPainter for host to draw a glyph’s OpenType SVG document with, or null when this backend has no SVG engine to render one with (a standalone raster canvas has none; a backend that layers an SVG engine on top of one overrides this). A caller that gets a real instance back typically caches it (it is reused for every SVG glyph the host draws); a caller that gets null may ask again next time - an override with nothing to offer should stay cheap to call repeatedly.
FamilyHasExplicitUnicodeRanges(string) Whether any face registered for family declares an explicit unicode-range - used by layout to decide when a fully-covered word must still be resolved per-codepoint to honor a ranged face.
GetColor(string) Resolve color value from given color name.
GetConicGradientBrush(PaintPoint, double, PaintColor[], double[]) Gets a brush that paints a conic gradient sweeping around center.
GetCssMediaType(IEnumerable<string>) The CSS media type (e.g. "print", "screen") this render context evaluates media queries against, chosen from mediaTypesAvailable.
GetFont(string, double, PaintFontStyle, Nullable<double>, Nullable<double>, Nullable<double>, string) Get font instance by given font family name, size and style.
GetFontForCodepoint(string, double, PaintFontStyle, Rune, Nullable<double>, Nullable<double>, Nullable<double>, string) Resolves a font for family restricted to faces that cover codepoint (its unicode-range or, absent that, its cmap coverage). Returns null when the family has no face covering the codepoint, so per-codepoint matching can move on to the next family in the font-family stack.
GetLinearGradientBrush(Rect, PaintColor, PaintColor, double) Get linear gradient color brush from color1 to color2. Legacy two-color convenience form - every real CSS/SVG gradient goes through the multi-stop overload below; this one only picks a start/end point from angle’s bucket and defers to it.
GetPen(Brush) Get a (not cached - brushes aren’t identity-stable/comparable the way colors are) pen that strokes with the given brush, e.g. for an SVG stroke="url(#gradient)".
GetPen(PaintColor) Get cached pen instance for the given color.
GetResourceStream(RUri) 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, RUri, FontFaceDescriptors, IReadOnlyList<RuneInterval>) then reports the load as failed rather than throwing). A backend that loads resources overrides this.
GetSolidBrush(PaintColor) Get cached solid brush instance for the given color.
GetSystemFallbackFontForCodepoint(double, PaintFontStyle, Rune, Nullable<double>, Nullable<double>, Nullable<double>, EmojiPresentation, string) The last-resort step of CSS Fonts 4 §5’s font matching algorithm: when no family in a box’s own font-family stack covers codepoint, resolves a font from any OTHER family this adapter knows about (every system-discovered and explicitly-registered font) that does. Returns null when nothing registered covers it either, so the caller keeps today’s .notdef/tofu-box behavior.
ImageFromStream(Stream) Create an Image object from the given stream.
IsFontExists(string) Check if the given font exists in the system by font family name.