@searsuite/sear-render-metrics
Platform-neutral text shaping and glyph measurement contracts.
Text shaping engines
- classRenderContextTextShaper
-
class RenderContextTextShaper extends TextShaperPortable fallback backed by the host's render-neutral text measurements.
- classTextMeasurementManager
-
Owns reusable semantic text measurements for one editor runtime.
constructor TextMeasurementManager(textShaper: TextShaper): TextMeasurementManagerproperty readonly symbol: typeof symbolstaticDI token for resolving the editor-local text measurement manager.
method clear(): voidClears semantic measurements without taking ownership of the text shaper.
method measureSpace(font: string): TextShapeResultMeasures 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.
constructor TextShaper(): TextShaperproperty readonly symbol: symbolstaticDI token for resolving the editor-local text-shaper provider.
method clearCache(): voidClears all cached shaping results owned by this adapter.
method shape(input: TextShapeInput): TextShapeResultShapes one homogeneous text run, reusing an identical cached request.
- classWebTextShaper
-
class WebTextShaper extends TextShaperBrowser-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
glyphsempty. CallclearCache()after an asynchronously loaded font becomes available.constructor WebTextShaper(context: WebTextShaperContext): WebTextShaperCreates a Web text shaper over a host-owned Canvas2D context.
- classWebTextShaperError
-
class WebTextShaperError extends SearErrorError raised when a Web text-shaping request cannot be represented by Canvas2D.
constructor WebTextShaperError(message: string, details?: SearErrorDetails): WebTextShaperErrorCreates a Web text-shaper error with stable diagnostics.
property readonly 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.
property direction: CanvasDirectionproperty font: stringproperty fontKerning?: CanvasFontKerningmethod measureText(text: string): TextMetricsmethod restore(): voidmethod save(): void - functioncreateWebTextShaperContext
-
createWebTextShaperContext(renderContext: RenderContext): WebTextShaperContextAdapts the shared render context to the Web shaper contract.
Shape and font values
- interfaceFontDescriptorInput
-
Structured font values supplied by editor configuration and host contexts.
property readonly fontFamily: stringproperty readonly fontSize: number - interfaceShapedCaretStop
-
A logical caret boundary produced by the shaping implementation.
property readonly textOffset: numberUTF-16 source-text offset for this caret boundary.
property readonly x: numberAdvance position in the shaped run's logical direction.
- interfaceShapedGlyph
-
One positioned glyph returned by a text-shaping implementation.
property readonly cluster: numberUTF-16 offset of the source text cluster represented by this glyph.
property readonly glyphId: numberproperty readonly xAdvance: numberproperty readonly xOffset: numberproperty readonly yAdvance: numberproperty readonly yOffset: number - interfaceShapedTextCluster
-
Mapping between source text and the glyph range generated for it.
property readonly glyphEnd: numberproperty readonly glyphStart: numberproperty readonly textEnd: numberproperty readonly textStart: number - interfaceTextShapeInput
-
Input passed to a text-shaper implementation. Offsets are UTF-16 offsets.
property readonly direction?: TextShapeDirectionproperty readonly features?: Readonly<Record<string, TextShapeFeatureValue>>Explicit OpenType feature settings, for example
{ liga: true, kern: true }.property readonly font: stringFont descriptor understood by the selected shaping implementation.
property readonly language?: stringISO/BCP language tag, when known.
property readonly script?: stringOpenType script tag, when known.
property readonly text: stringproperty readonly 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.
property readonly caretStops: readonly ShapedCaretStop[]property readonly clusters: readonly ShapedTextCluster[]property readonly fontAscent?: numberproperty readonly fontDescent?: numberproperty readonly fontLineGap?: numberproperty readonly glyphs: readonly ShapedGlyph[]property readonly height: numberTotal vertical advance, normally zero for horizontal text.
property readonly width: numberTotal 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 | numberOpenType feature value accepted by a text-shaper adapter.
- functioncreateFontDescriptor
-
createFontDescriptor(input: FontDescriptorInput): stringCreates the low-level font descriptor consumed by text shaping and rendering.
No matching API entries.