← All packages

@searsuite/sear-render-metrics

Platform-neutral text shaping and glyph measurement contracts.

Text shaping engines

classRenderContextTextShaper
class RenderContextTextShaper extends TextShaper

Portable fallback backed by the host's render-neutral text measurements.

Inherited members 3

Inherited from TextShaper.

classTextMeasurementManager

Owns reusable semantic text measurements for one editor runtime.

constructorTextMeasurementManager(textShaper: TextShaper): TextMeasurementManager
propertyreadonly symbol: typeof symbolstatic

DI token for resolving the editor-local text measurement manager.

methodclear(): void

Clears semantic measurements without taking ownership of the text shaper.

methodmeasureSpace(font: string): TextShapeResult

Measures one space for a font and reuses the editor-local result.

classTextShaper

Abstract adapter boundary for HarfBuzz, Skia, browser-native, or platform text-shaping implementations.

Concrete adapters translate the normalized request to their shaping library and return engine-neutral glyph/cluster data.

constructorTextShaper(): TextShaper
propertyreadonly symbol: symbolstatic

DI token for resolving the editor-local text-shaper provider.

methodclearCache(): void

Clears all cached shaping results owned by this adapter.

methodshape(input: TextShapeInput): TextShapeResult

Shapes one homogeneous text run, reusing an identical cached request.

classWebTextShaper
class WebTextShaper extends TextShaper

Browser-native TextShaper backed by Canvas2D.

Canvas2D preserves the browser's native shaping for complete text runs but does not expose glyph ids or glyph ranges. Results therefore contain grapheme clusters and caret measurements while leaving glyphs empty. Call clearCache() after an asynchronously loaded font becomes available.

constructorWebTextShaper(context: WebTextShaperContext): WebTextShaper

Creates a Web text shaper over a host-owned Canvas2D context.

Inherited members 3

Inherited from TextShaper.

classWebTextShaperError
class WebTextShaperError extends SearError

Error raised when a Web text-shaping request cannot be represented by Canvas2D.

constructorWebTextShaperError(message: string, details?: SearErrorDetails): WebTextShaperError

Creates a Web text-shaper error with stable diagnostics.

propertyreadonly code: "WEB_TEXT_SHAPER_ERROR"

Stable machine-readable identifier for this error category.

Inherited members 9

Inherited from SearError.

interfaceWebTextShaperContext

Native text settings and operations required by the Web adapter.

functioncreateWebTextShaperContext
createWebTextShaperContext(renderContext: RenderContext): WebTextShaperContext

Adapts the shared render context to the Web shaper contract.

Shape and font values

interfaceFontDescriptorInput

Structured font values supplied by editor configuration and host contexts.

interfaceShapedCaretStop

A logical caret boundary produced by the shaping implementation.

propertyreadonly textOffset: number

UTF-16 source-text offset for this caret boundary.

propertyreadonly x: number

Advance position in the shaped run's logical direction.

interfaceShapedGlyph

One positioned glyph returned by a text-shaping implementation.

propertyreadonly cluster: number

UTF-16 offset of the source text cluster represented by this glyph.

propertyreadonly glyphId: number
propertyreadonly xAdvance: number
propertyreadonly xOffset: number
propertyreadonly yAdvance: number
propertyreadonly yOffset: number
interfaceShapedTextCluster

Mapping between source text and the glyph range generated for it.

interfaceTextShapeInput

Input passed to a text-shaper implementation. Offsets are UTF-16 offsets.

propertyreadonly direction?: TextShapeDirection
propertyreadonly features?: Readonly<Record<string, TextShapeFeatureValue>>

Explicit OpenType feature settings, for example { liga: true, kern: true }.

propertyreadonly font: string

Font descriptor understood by the selected shaping implementation.

propertyreadonly language?: string

ISO/BCP language tag, when known.

propertyreadonly script?: string

OpenType script tag, when known.

propertyreadonly text: string
propertyreadonly variations?: Readonly<Record<string, number>>

Variation-axis values for variable fonts, keyed by four-character axis tag.

interfaceTextShapeResult

Engine-neutral result of shaping one homogeneous text run.

propertyreadonly caretStops: readonly ShapedCaretStop[]
propertyreadonly clusters: readonly ShapedTextCluster[]
propertyreadonly fontAscent?: number
propertyreadonly fontDescent?: number
propertyreadonly fontLineGap?: number
propertyreadonly glyphs: readonly ShapedGlyph[]
propertyreadonly height: number

Total vertical advance, normally zero for horizontal text.

propertyreadonly width: number

Total horizontal advance of the shaped run.

typeTextShapeDirection
type TextShapeDirection = "ltr" | "rtl"

Direction of a shaped text run in logical document order.

typeTextShapeFeatureValue
type TextShapeFeatureValue = boolean | number

OpenType feature value accepted by a text-shaper adapter.

functioncreateFontDescriptor
createFontDescriptor(input: FontDescriptorInput): string

Creates the low-level font descriptor consumed by text shaping and rendering.