/** * MSDF font atlas definition — parses `msdf-atlas-gen` style JSON (the format emitted by * `tools/msdf-atlas.mjs`) or legacy BMFont JSON into a normalized, em-relative glyph table. * * All plane metrics (glyph bounds, advances, line metrics) are stored in em units so layout * is a plain multiply by `fontSize`; atlas bounds are stored as UV rects for the companion * KTX2 texture (raw RGBA8, flipY = false → v grows downward from the top row). * * @module MSDFFont */ /** Four normalized atlas or plane coordinates in left/bottom/right/top order. */ export type MSDFRect = [left: number, bottom: number, right: number, top: number]; /** Four texture coordinates in u0/v0/u1/v1 order. */ export type MSDFUVRect = [u0: number, v0: number, u1: number, v1: number]; /** One normalized glyph entry stored by {@link MSDFFont}. */ export interface MSDFGlyph { /** Horizontal pen advance in em units. */ advance: number; /** Glyph plane bounds in em units relative to the baseline. */ planeBounds: MSDFRect; /** Glyph rectangle within the companion atlas texture. */ uvRect: MSDFUVRect; } /** Options applied while normalizing font metadata. */ export interface ParseMSDFFontOptions { /** Whether atlas V coordinates must account for a vertically flipped texture upload. */ flipY?: boolean; } /** * A parsed MSDF font atlas: glyph metrics in em units plus UV rects into the atlas texture. * * @class MSDFFont * @short Normalized MSDF atlas metrics (glyphs, kernings, line metrics) for text layout. * @category Text * @tags WebGPU, WebGL */ export declare class MSDFFont { /** Normalized glyph metrics keyed by Unicode code point. */ glyphs: Map; /** Kerning adjustments in em units keyed by `left:right` code-point pairs. */ kernings: Map; /** Default line-box height in em units. */ lineHeight: number; /** Ascender height above the baseline in em units. */ ascender: number; /** Descender position below the baseline in em units. */ descender: number; /** Recommended underline position in em units. */ underlineY: number; /** Recommended underline thickness in em units. */ underlineThickness: number; /** Signed-distance range encoded by the atlas, measured in atlas pixels. */ distanceRange: number; /** Source font size used to generate the atlas, measured in pixels per em. */ size: number; /** Atlas texture width in pixels. */ atlasWidth: number; /** Atlas texture height in pixels. */ atlasHeight: number; /** Informational font-family name from the source metadata. */ name: string; /** Creates an empty normalized font record with safe fallback metrics. */ constructor(); /** * Reports whether the atlas contains a glyph for a Unicode code point. * * @param {number} codePoint * @returns {boolean} Whether the atlas contains this glyph. */ has(codePoint: number): boolean; /** * Looks up a glyph with fallback to U+FFFD then '?'. Returns null only when the atlas has * neither the glyph nor a fallback (e.g. an icon-only atlas). * * @param {number} codePoint * @returns {{advance: number, planeBounds: number[], uvRect: number[]}|null} */ getGlyph(codePoint: number): MSDFGlyph | null; /** * Reads the kerning adjustment for two adjacent Unicode code points. * * @param {number} left - Codepoint of the left glyph. * @param {number} right - Codepoint of the right glyph. * @returns {number} Kerning adjustment in em (0 when the pair is unknown). */ getKerning(left: number, right: number): number; } /** * Parses MSDF font metadata JSON into an {@link MSDFFont}. * * Accepts the `msdf-atlas-gen` layout (`{ atlas, metrics, glyphs: [{ unicode, advance, * planeBounds, atlasBounds }], kerning }`) — em-relative, `yOrigin` top or bottom — or the * BMFont layout (`{ info, common, chars: [{ id, x, y, width, height, xoffset, yoffset, * xadvance }], kernings }`) — pixel-relative, normalized here by `info.size`. * * @param {Object} json - Parsed font metadata. * @param {Object} [options] * @param {boolean} [options.flipY=false] - Set true when the atlas texture uploads with * `flipY` (e.g. PNG via TextureLoader); raw KTX2 `DataTexture`s do not flip. * @returns {MSDFFont} * @short Parse msdf-atlas-gen or BMFont JSON into a normalized MSDFFont. * @category Text * @tags WebGPU, WebGL */ export declare function parseMSDFFont(json: unknown, { flipY }?: ParseMSDFFontOptions): MSDFFont;