@mocanvas/mocanvas · function

textToSvg

declare function textToSvg(source: RichTextSource, box: SvgTextBox, opts: SvgTextOptions): string

Render source inside box. Returns an empty string for an empty label. Lines are positioned with dominant-baseline="central" so vertical centring does not depend on font metrics.

Accepts either spelling of a label: a plain string, or the rich-text document the store may hold in props.richText. A document is exported run by run — bold, italic, underlined and struck-through spans and links survive into the SVG — while a plain string takes the single-<tspan>-per-line path it always did.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.