/** * TrueType Hinting Types * * Based on FreeType's ttinterp.h and ttobjs.h */ /** * 26.6 fixed-point number (used for coordinates) */ export type F26Dot6 = number; /** * 2.14 fixed-point number (used for unit vectors) */ export type F2Dot14 = number; /** * Unit vector in 2.14 format */ export interface UnitVector { x: F2Dot14; y: F2Dot14; } /** * Point coordinate */ export interface Point { x: F26Dot6; y: F26Dot6; } /** * Rounding mode for ROUND instruction */ export declare enum RoundMode { ToHalfGrid = 0, ToGrid = 1, ToDoubleGrid = 2, DownToGrid = 3, UpToGrid = 4, Off = 5, Super = 6, Super45 = 7 } /** * Touch flags for points */ export declare enum TouchFlag { X = 16, Y = 32, Both = 48 } /** * Render mode used for GETINFO responses. */ export type HintRenderMode = "mono" | "gray" | "lcd" | "lcd_v"; /** * Glyph zone - holds glyph points */ export interface GlyphZone { /** Number of points */ nPoints: number; /** Number of contours */ nContours: number; /** Original point positions (before hinting) */ org: Point[]; /** Current point positions (after hinting) */ cur: Point[]; /** Original unscaled positions */ orus: Point[]; /** Touch flags per point */ tags: Uint8Array; /** Contour end indices */ contours: Uint16Array; } /** * TrueType Graphics State * * Contains all state variables that control how instructions operate */ export interface GraphicsState { rp0: number; rp1: number; rp2: number; dualVector: UnitVector; projVector: UnitVector; freeVector: UnitVector; loop: number; minimumDistance: F26Dot6; roundState: RoundMode; autoFlip: boolean; controlValueCutIn: F26Dot6; singleWidthCutIn: F26Dot6; singleWidthValue: F26Dot6; deltaBase: number; deltaShift: number; instructControl: number; scanControl: number; scanType: number; gep0: number; gep1: number; gep2: number; period: F26Dot6; phase: F26Dot6; threshold: F26Dot6; } /** * Create default graphics state */ export declare function createDefaultGraphicsState(): GraphicsState; /** * Function definition (from FDEF instruction) */ export interface FunctionDef { /** Function number */ id: number; /** Start offset in bytecode */ start: number; /** End offset (just after ENDF) */ end: number; /** Active (has been defined) */ active: boolean; /** Which code range */ range: CodeRange; } /** * Instruction definition (from IDEF instruction) */ export interface InstructionDef { /** Opcode being redefined */ opcode: number; /** Start offset */ start: number; /** End offset */ end: number; /** Active */ active: boolean; /** Code range */ range: CodeRange; } /** * Code range type */ export declare enum CodeRange { None = 0, Font = 1,// fpgm table CVT = 2,// prep table Glyph = 3 } /** * Call stack record */ export interface CallRecord { /** Caller's instruction pointer */ callerIP: number; /** Caller's code range */ callerRange: CodeRange; /** Function definition */ def: FunctionDef; /** Loop count (for LOOPCALL) */ count: number; } /** * Execution context for the TrueType interpreter */ export interface ExecContext { GS: GraphicsState; defaultGS: GraphicsState; zp0: GlyphZone; zp1: GlyphZone; zp2: GlyphZone; twilight: GlyphZone; pts: GlyphZone; stack: Int32Array; stackTop: number; IP: number; code: Uint8Array; codeSize: number; currentRange: CodeRange; opcode: number; numArgs: number; cvt: Int32Array; cvtSize: number; storage: Int32Array; storageSize: number; FDefs: FunctionDef[]; maxFDefs: number; IDefs: InstructionDef[]; maxIDefs: number; callStack: CallRecord[]; callStackTop: number; maxCallStack: number; codeRanges: Map; ppem: number; pointSize: number; scale: number; scaleFix: number; lightMode: boolean; grayscale: boolean; renderMode: HintRenderMode; backwardCompatibility: number; isComposite: boolean; error: string | null; instructionCount: number; maxInstructions: number; } /** * Create an empty glyph zone */ export declare function createGlyphZone(maxPoints: number, maxContours: number): GlyphZone; /** * Create execution context */ export declare function createExecContext(maxStack?: number, maxStorage?: number, maxFDefs?: number, maxIDefs?: number, maxCallStack?: number, maxTwilightPoints?: number): ExecContext; /** * TrueType Opcodes */ export declare const Opcode: { readonly NPUSHB: 64; readonly NPUSHW: 65; readonly PUSHB_0: 176; readonly PUSHB_1: 177; readonly PUSHB_2: 178; readonly PUSHB_3: 179; readonly PUSHB_4: 180; readonly PUSHB_5: 181; readonly PUSHB_6: 182; readonly PUSHB_7: 183; readonly PUSHW_0: 184; readonly PUSHW_1: 185; readonly PUSHW_2: 186; readonly PUSHW_3: 187; readonly PUSHW_4: 188; readonly PUSHW_5: 189; readonly PUSHW_6: 190; readonly PUSHW_7: 191; readonly RS: 67; readonly WS: 66; readonly RCVT: 69; readonly WCVTP: 68; readonly WCVTF: 112; readonly DUP: 32; readonly POP: 33; readonly CLEAR: 34; readonly SWAP: 35; readonly DEPTH: 36; readonly CINDEX: 37; readonly MINDEX: 38; readonly ROLL: 138; readonly ADD: 96; readonly SUB: 97; readonly DIV: 98; readonly MUL: 99; readonly ABS: 100; readonly NEG: 101; readonly FLOOR: 102; readonly CEILING: 103; readonly MAX: 139; readonly MIN: 140; readonly LT: 80; readonly LTEQ: 81; readonly GT: 82; readonly GTEQ: 83; readonly EQ: 84; readonly NEQ: 85; readonly ODD: 86; readonly EVEN: 87; readonly AND: 90; readonly OR: 91; readonly NOT: 92; readonly IF: 88; readonly ELSE: 27; readonly EIF: 89; readonly JMPR: 28; readonly JROT: 120; readonly JROF: 121; readonly FDEF: 44; readonly ENDF: 45; readonly CALL: 43; readonly LOOPCALL: 42; readonly IDEF: 137; readonly SVTCA_Y: 0; readonly SVTCA_X: 1; readonly SPVTCA_Y: 2; readonly SPVTCA_X: 3; readonly SFVTCA_Y: 4; readonly SFVTCA_X: 5; readonly SPVTL_0: 6; readonly SPVTL_1: 7; readonly SFVTL_0: 8; readonly SFVTL_1: 9; readonly SDPVTL_0: 134; readonly SDPVTL_1: 135; readonly SPVFS: 10; readonly SFVFS: 11; readonly GPV: 12; readonly GFV: 13; readonly SFVTPV: 14; readonly ISECT: 15; readonly SRP0: 16; readonly SRP1: 17; readonly SRP2: 18; readonly SZP0: 19; readonly SZP1: 20; readonly SZP2: 21; readonly SZPS: 22; readonly SLOOP: 23; readonly RTG: 24; readonly RTHG: 25; readonly SMD: 26; readonly RDTG: 125; readonly RUTG: 124; readonly ROFF: 122; readonly SROUND: 118; readonly S45ROUND: 119; readonly SCVTCI: 29; readonly SSWCI: 30; readonly SSW: 31; readonly FLIPON: 77; readonly FLIPOFF: 78; readonly SANGW: 126; readonly SDB: 94; readonly SDS: 95; readonly GC_0: 70; readonly GC_1: 71; readonly SCFS: 72; readonly MD_0: 73; readonly MD_1: 74; readonly MPPEM: 75; readonly MPS: 76; readonly FLIPPT: 128; readonly FLIPRGON: 129; readonly FLIPRGOFF: 130; readonly SHP_0: 50; readonly SHP_1: 51; readonly SHC_0: 52; readonly SHC_1: 53; readonly SHZ_0: 54; readonly SHZ_1: 55; readonly SHPIX: 56; readonly IP: 57; readonly MSIRP_0: 58; readonly MSIRP_1: 59; readonly ALIGNRP: 60; readonly RTDG: 61; readonly MIAP_0: 62; readonly MIAP_1: 63; readonly ALIGNPTS: 39; readonly UTP: 41; readonly MDAP_0: 46; readonly MDAP_1: 47; readonly IUP_Y: 48; readonly IUP_X: 49; readonly DELTAP1: 93; readonly DELTAP2: 113; readonly DELTAP3: 114; readonly DELTAC1: 115; readonly DELTAC2: 116; readonly DELTAC3: 117; readonly ROUND_0: 104; readonly ROUND_1: 105; readonly ROUND_2: 106; readonly ROUND_3: 107; readonly NROUND_0: 108; readonly NROUND_1: 109; readonly NROUND_2: 110; readonly NROUND_3: 111; readonly GETINFO: 136; readonly INSTCTRL: 142; readonly SCANCTRL: 133; readonly SCANTYPE: 141; readonly AA: 127; readonly DEBUG: 79; readonly MDRP_BASE: 192; readonly MIRP_BASE: 224; }; /** * Number of values popped from stack for each opcode */ export declare const OpcodePops: Record;