Table of Contents

Interface IRasterizer

Namespace
KernSmith.Rasterizer
Assembly
KernSmith.dll

Rasterizes font glyphs into bitmaps for texture atlas packing.

public interface IRasterizer : IDisposable
Inherited Members

Properties

Capabilities

Describes what this rasterizer backend supports.

IRasterizerCapabilities Capabilities { get; }

Property Value

IRasterizerCapabilities

Methods

GetFontMetrics(RasterOptions)

Returns rasterizer-provided font-wide metrics. Returns null to fall back to TTF table calculation.

RasterizerFontMetrics? GetFontMetrics(RasterOptions options)

Parameters

options RasterOptions

Returns

RasterizerFontMetrics

GetGlyphMetrics(int, RasterOptions)

Gets glyph metrics without rasterizing. Returns null if the glyph is missing from the font.

GlyphMetrics? GetGlyphMetrics(int codepoint, RasterOptions options)

Parameters

codepoint int

The Unicode character code.

options RasterOptions

Size, DPI, and other settings.

Returns

GlyphMetrics?

GetKerningPairs(RasterOptions)

Returns rasterizer-provided kerning pairs already scaled to pixel values. Returns null to fall back to TTF GPOS/kern table parser.

IReadOnlyList<ScaledKerningPair>? GetKerningPairs(RasterOptions options)

Parameters

options RasterOptions

Returns

IReadOnlyList<ScaledKerningPair>

LoadFont(ReadOnlyMemory<byte>, int)

Loads a font from raw file bytes for subsequent rasterization.

void LoadFont(ReadOnlyMemory<byte> fontData, int faceIndex = 0)

Parameters

fontData ReadOnlyMemory<byte>

The font file bytes.

faceIndex int

Which face to use in a .ttc font collection. Usually 0.

LoadSystemFont(string)

Loads a system-installed font by family name for subsequent rasterization. Not all backends support this — the default throws NotSupportedException. Check SupportsSystemFonts before calling.

void LoadSystemFont(string familyName)

Parameters

familyName string

The font family name (e.g., "Arial").

RasterizeAll(IEnumerable<int>, RasterOptions)

Renders multiple characters to bitmaps, skipping any that are missing from the font.

IReadOnlyList<RasterizedGlyph> RasterizeAll(IEnumerable<int> codepoints, RasterOptions options)

Parameters

codepoints IEnumerable<int>

The Unicode character codes to render.

options RasterOptions

Size, DPI, anti-aliasing, and other rendering settings.

Returns

IReadOnlyList<RasterizedGlyph>

RasterizeGlyph(int, RasterOptions)

Renders a single character to a bitmap. Returns null if the glyph is missing from the font.

RasterizedGlyph? RasterizeGlyph(int codepoint, RasterOptions options)

Parameters

codepoint int

The Unicode character code to render.

options RasterOptions

Size, DPI, anti-aliasing, and other rendering settings.

Returns

RasterizedGlyph

RasterizeOutlineLayer(int, RasterOptions, int, OutlineShape, float)

Renders the outline layer of a character for Vector: the coverage of the glyph dilated by width pixels — everything RasterizeGlyph(int, RasterOptions) would draw for the same options, plus every point within width pixels of its contours. The pipeline colors it, backs the body with it and composites it exactly where its bitmap outline would go — clipped to the glyph's box grown by width — so the metrics must place the bitmap in the same pen-relative frame as RasterizeGlyph(int, RasterOptions). Returns null when the backend cannot draw this glyph's layer, and the pipeline then uses its bitmap outline for it. The default returns null for every glyph.

RasterizedGlyph? RasterizeOutlineLayer(int codepoint, RasterOptions options, int width, OutlineShape shape, float heightScale = 1)

Parameters

codepoint int

The Unicode character code.

options RasterOptions

The same options the glyph itself is rendered with.

width int

Outline width in pixels: how far the layer extends past the glyph.

shape OutlineShape

The pen: round (Euclidean distance), square (Chebyshev) or plus (Manhattan).

heightScale float

The vertical stretch the pipeline applies to the glyph and this layer afterwards (HeightPercent / 100). Draw the ring width pixels wide and width / heightScale pixels tall, so that once stretched it is width pixels all round.

Returns

RasterizedGlyph

SelectColorPalette(int)

Selects a color palette by index for color font rendering. Only called when SupportsColorFonts is true.

void SelectColorPalette(int paletteIndex)

Parameters

paletteIndex int

Zero-based palette index.

SetVariationAxes(IReadOnlyList<VariationAxis>, Dictionary<string, float>)

Applies variable font axis values. Only called when SupportsVariableFonts is true.

void SetVariationAxes(IReadOnlyList<VariationAxis> fvarAxes, Dictionary<string, float> userAxes)

Parameters

fvarAxes IReadOnlyList<VariationAxis>

The axes defined in the font's fvar table, in order.

userAxes Dictionary<string, float>

User-specified axis tag/value pairs (e.g., "wght" = 700).