import { type Font } from './font.ts'; import { type GlyphRun } from './glyph-run.ts'; /** * Options for text shaping. */ export type ShapeOptions = { /** * The OpenType script tag (e.g., 'latn' for Latin, 'arab' for Arabic). * If not specified, or if the specified script is not found in the font, * the 'DFLT' script will be used if available. * * See the OpenType specification for a list of script tags: * https://learn.microsoft.com/en-us/typography/opentype/spec/scripttags */ scriptTag?: string; /** * The OpenType language system tag (e.g., 'ENG' for English, 'DEU' for German). * If not specified, or if the specified language is not found in the font, * the default language for the script will be used. * * See the OpenType specification for a list of language system tags: * https://learn.microsoft.com/en-us/typography/opentype/spec/languagetags */ langSysTag?: string; /** * Whether to enable the default font features (ligatures and kerning). * Defaults to `true`. * To disable all default features, set this to `false`. * * Example: * ```typescript * const glyphRun = shaper.shape('Difficult Waffle', { defaultFeatures: false }); * ``` */ defaultFeatures?: boolean; /** * Font features to apply beyond the defaults. * To enable additional features, set them to `true`. * To disable specific default features, set them to `false`. * * Example: * ```typescript * const glyphRun = shaper.shape('Difficult Waffle', { * features: { * 'smcp': true, // Enable small caps * 'ss01': true, // Enable stylistic set 1 * }, * }); * ``` */ features?: Record; }; /** * Performs text shaping using OpenType GSUB and GPOS tables. * * Text shaping converts a Unicode string into a sequence of positioned * glyphs. This includes: * - Character to glyph mapping (via cmap) * - Glyph substitution (GSUB): ligatures, contextual alternates, etc. * - Glyph positioning (GPOS): kerning adjustments, mark positioning, etc. * * Example: * ```typescript * const shaper = new TextShaper(font, { scriptTag: 'latn', langSysTag: 'ENG' }); * const glyphRun = shaper.shape('Difficult Waffle'); * ``` */ export declare class TextShaper { private readonly defaultOptions; private readonly hmtxTable; private readonly gsubProcessor; private readonly gposProcessor; private readonly kernTable; private readonly gposHasKernCache; /** The font used for shaping. */ readonly font: Font; /** * Creates a new TextShaper for the given font. * * @param font - The font to use for shaping. * @param defaultOptions - Default shaping options for all `shape()` calls. */ constructor(font: Font, defaultOptions?: ShapeOptions); /** * Shapes the given text into a GlyphRun, applying GSUB and GPOS features. * * @param text - The text to shape. * @param options - Shaping options to override the defaults. * @returns The resulting GlyphRun with substituted and positioned glyphs. */ shape(text: string, options?: ShapeOptions): GlyphRun; private gposHasKern; private createGlyphRun; }