Skip to main content

TextRenderer and glyph renderers

Namespace: PinataLabs.Typography. Guides: Glyph renderers, Color fonts.

TextRenderer​

public class TextRenderer

Lays out text and sends the glyph outlines to an IGlyphRenderer.

MemberDescription
TextRenderer(IGlyphRenderer renderer)Makes a text renderer that renders to renderer.
RenderText(string text, TextOptions options)Lays out and renders text.
RenderText(ReadOnlySpan<char> text, TextOptions options)Lays out and renders text.
static RenderTextTo(IGlyphRenderer renderer, string text, TextOptions options)Lays out and renders text to renderer.
static RenderTextTo(IGlyphRenderer renderer, ReadOnlySpan<char> text, TextOptions options)Lays out and renders text to renderer.

IGlyphRendererExtensions​

MemberDescription
Render(this IGlyphRenderer renderer, ReadOnlySpan<char> text, TextOptions options)Renders text to renderer. Returns renderer.

IGlyphRenderer​

public interface IGlyphRenderer

A surface that receives glyph outlines. All points are in pixels at the DPI of the layout, with the y-axis pointing down.

MemberDescription
void BeginText(in FontRectangle bounds)Called once, before the first glyph. bounds is the ink box of the text.
bool BeginGlyph(in FontRectangle bounds, in GlyphRendererParameters parameters)Called for each glyph. bounds is the ink box of the glyph. Return true to receive the outline and decorations, false to skip them.
void BeginFigure()Starts a closed contour.
void MoveTo(Vector2 point)Sets the first point of the contour.
void LineTo(Vector2 point)Adds a straight line from the current point.
void QuadraticBezierTo(Vector2 secondControlPoint, Vector2 point)Adds a quadratic Bézier curve from the current point.
void CubicBezierTo(Vector2 secondControlPoint, Vector2 thirdControlPoint, Vector2 point)Adds a cubic Bézier curve from the current point.
void EndFigure()Closes the contour.
TextDecorations EnabledDecorations()Returns the decorations that the renderer wants for the current glyph.
void SetDecoration(TextDecorations textDecorations, Vector2 start, Vector2 end, float thickness)Gives one decoration line for the current glyph. start and end are on one edge of the line.
void EndGlyph()Called after each glyph, also when BeginGlyph returned false.
void EndText()Called once, after the last glyph.

In each curve method, the first control point is the current point, so it is not passed. That is why the parameters start at secondControlPoint.

IColorGlyphRenderer​

public interface IColorGlyphRenderer : IGlyphRenderer

A renderer that supports color glyphs.

MemberDescription
void SetColor(GlyphColor color)Called after BeginGlyph for each layer of a color glyph, before its outline.

GlyphRendererParameters​

public readonly struct GlyphRendererParameters : IEquatable<GlyphRendererParameters>

Identifies a glyph. Two values are equal when they describe the same outline at the same size, so the value can be a cache key.

PropertyTypeDescription
GlyphIdushortThe index of the glyph in its font.
CodePointCodePointThe code point that the glyph came from.
FontstringThe full name of the font, in upper case.
FontStyleFontStyleThe style of the font.
PointSizefloatThe size in points.
DpifloatThe DPI of the layout.
GlyphTypeGlyphTypeStandard, Fallback or ColrLayer.
GlyphColorGlyphColorThe color of a color layer.
LayoutModeGlyphLayoutModeHorizontal, Vertical or VerticalRotated.
TextRunTextRunThe run that the glyph is in.

Equality compares GlyphId, Font, FontStyle, PointSize, Dpi, GlyphType, GlyphColor, LayoutMode, and the TextAttributes and TextDecorations of the run.