/** * Pure text layout for MSDF fonts — no three.js objects, just glyph placements. * * Two entry points: * - {@link layoutMSDFLine} lays out a single pre-broken line (the DOM-sync path, where the * browser already decided the line breaks). * - {@link layoutMSDFText} lays out a whole block: wrapping (spaces + CJK with a minimal * kinsoku set), alignment, line stacking. * * All output coordinates are in `fontSize` units: x grows right from the line start, y is * the baseline (y-up, so subsequent lines sit at negative y). * * @module MSDFTextLayout */ import type { MSDFFont, MSDFGlyph } from './MSDFFont.cjs'; /** Shared sizing and spacing options for a single MSDF line. */ export interface MSDFLineLayoutOptions { fontSize?: number; letterSpacing?: number; } /** One glyph placement on a single baseline. */ export interface MSDFLineGlyph { codePoint: number; x: number; glyph: MSDFGlyph; } /** Result of laying out one unwrapped line. */ export interface MSDFLineLayout { glyphs: MSDFLineGlyph[]; width: number; } /** Horizontal alignment supported by block layout. */ export type MSDFTextAlign = 'left' | 'center' | 'right'; /** Wrapping and line-stacking options for a text block. */ export interface MSDFTextLayoutOptions extends MSDFLineLayoutOptions { lineHeight?: number; maxWidth?: number; align?: MSDFTextAlign; } /** One glyph placement in a laid-out block. */ export interface MSDFTextGlyph extends MSDFLineGlyph { y: number; line: number; } /** One line's measured width and baseline. */ export interface MSDFTextLine { width: number; y: number; } /** Complete wrapping/alignment result. */ export interface MSDFTextLayout { glyphs: MSDFTextGlyph[]; width: number; height: number; lines: MSDFTextLine[]; } /** * Lays out one line of text (no wrapping). Kerning and letter-spacing are applied between * glyphs; trailing letter-spacing is not counted in the width (CSS behaviour). * * @param {import('./MSDFFont.js').MSDFFont} font * @param {string} text - A single line (newlines are treated as missing glyphs). * @param {Object} [options] * @param {number} [options.fontSize=1] - Units per em. * @param {number} [options.letterSpacing=0] - Extra advance per glyph, in the same units. * @returns {{glyphs: Array<{codePoint: number, x: number, glyph: Object}>, width: number}} * @short Single-line MSDF glyph layout (kerning + letter-spacing). * @category Text * @tags WebGPU, WebGL */ export declare function layoutMSDFLine(font: MSDFFont, text: string, { fontSize, letterSpacing }?: MSDFLineLayoutOptions): MSDFLineLayout; /** * Lays out a text block with wrapping, alignment and line stacking. * * @param {import('./MSDFFont.js').MSDFFont} font * @param {string} text - May contain `\n` for hard breaks. * @param {Object} [options] * @param {number} [options.fontSize=1] - Units per em. * @param {number} [options.letterSpacing=0] - Extra advance per glyph. * @param {number} [options.lineHeight=0] - Line box height in units; 0 → font's default * (`font.lineHeight * fontSize`). * @param {number} [options.maxWidth=Infinity] - Wrap width in units. * @param {('left'|'center'|'right')} [options.align='left'] * @returns {{ * glyphs: Array<{codePoint: number, x: number, y: number, line: number, glyph: Object}>, * width: number, height: number, * lines: Array<{width: number, y: number}> * }} Positions in units, first baseline at y = 0, later lines below (negative y). * @short Multi-line MSDF layout: wrapping (spaces + CJK kinsoku), alignment, stacking. * @category Text * @tags WebGPU, WebGL */ export declare function layoutMSDFText(font: MSDFFont, text: string, options?: MSDFTextLayoutOptions): MSDFTextLayout;