/** * TrueType Hinting Program Execution * * This module handles the setup and execution of TrueType hinting programs: * - fpgm: Font program (executed once when font is loaded) * - prep: CVT program (executed when size changes) * - glyph: Per-glyph instructions */ import { type ExecContext } from "./types.ts"; /** * Hinting engine for a font */ export interface HintingEngine { /** Execution context */ ctx: ExecContext; /** Units per EM from font */ unitsPerEM: number; /** Original CVT values in font units */ cvtOriginal?: Int32Array; /** Scaled CVT baseline after prep */ cvtBase?: Int32Array; /** Has fpgm been executed */ fpgmExecuted: boolean; /** Current ppem (prep needs re-run if this changes) */ currentPpem: number; } /** * Create a hinting engine for a font */ export declare function createHintingEngine(unitsPerEM: number, maxStack?: number, maxStorage?: number, maxFDefs?: number, maxTwilightPoints?: number, cvtValues?: Int32Array): HintingEngine; /** * Load font program (fpgm table) */ export declare function loadFontProgram(engine: HintingEngine, fpgm: Uint8Array): void; /** * Load CVT program (prep table) */ export declare function loadCVTProgram(engine: HintingEngine, prep: Uint8Array): void; /** * Execute fpgm (should be called once after font load) */ export declare function executeFontProgram(engine: HintingEngine): string | null; /** * Set up for a specific size and execute prep if needed */ export declare function setSize(engine: HintingEngine, ppem: number, pointSize: number): string | null; /** * Glyph outline for hinting */ export interface GlyphOutline { /** X coordinates in font units */ xCoords: number[]; /** Y coordinates in font units */ yCoords: number[]; /** Point flags (bit 0 = on-curve) */ flags: Uint8Array; /** End point indices for each contour */ contourEnds: number[]; /** Glyph instructions */ instructions: Uint8Array; /** Left side bearing in font units (for phantom point) */ lsb?: number; /** Advance width in font units (for phantom point) */ advanceWidth?: number; /** Top side bearing in font units (for vertical phantom point) */ tsb?: number; /** Advance height in font units (for vertical phantom point) */ advanceHeight?: number; /** True if glyph is composite */ isComposite?: boolean; } /** * Hinted glyph result */ export interface HintedGlyph { /** Hinted X coordinates in 26.6 pixels */ xCoords: number[]; /** Hinted Y coordinates in 26.6 pixels */ yCoords: number[]; /** Point flags */ flags: Uint8Array; /** Contour end indices */ contourEnds: number[]; /** Error message if hinting failed */ error: string | null; } /** * Hint a glyph */ export declare function hintGlyph(engine: HintingEngine, outline: GlyphOutline): HintedGlyph; /** * Convert hinted coordinates from 26.6 to floating point pixels */ export declare function hintedToPixels(coords: number[]): number[];