/** * TrueType font file parser. * * Reads a TrueType (.ttf) or TrueType-flavored OpenType (.otf) font file * and extracts the tables needed for PDF font embedding: * - head: font header (units per em, index format) * - hhea: horizontal header (ascent, descent, line gap, number of hmetrics) * - maxp: maximum profile (number of glyphs) * - OS/2: OS/2 and Windows metrics (weights, widths, unicode ranges) * - cmap: character-to-glyph mapping (we use format 4 for BMP or format 12 for full Unicode) * - hmtx: horizontal metrics (advance widths per glyph) * - post: PostScript name mapping * - loca: glyph location index (offsets into glyf table) * - glyf: glyph outlines (needed for subsetting) * - name: naming table (font family name, style, etc.) * * TrueType is Big Endian throughout. * * @see https://docs.microsoft.com/en-us/typography/opentype/spec/ */ /** * Parsed TrueType font data needed for PDF embedding. */ export interface TtfFont { /** Raw font file bytes */ readonly data: Uint8Array; /** Font family name (from name table, nameID 1) */ readonly familyName: string; /** PostScript name (from name table, nameID 6) */ readonly postScriptName: string; /** Units per em (from head table) */ readonly unitsPerEm: number; /** Ascent in font units (from OS/2 sTypoAscender or hhea ascent) */ readonly ascent: number; /** Descent in font units (negative, from OS/2 sTypoDescender or hhea descent) */ readonly descent: number; /** Cap height in font units (from OS/2 sCapHeight, or estimated) */ readonly capHeight: number; /** Italic angle in degrees (from post table) */ readonly italicAngle: number; /** Font flags for PDF font descriptor */ readonly flags: number; /** Font bounding box [xMin, yMin, xMax, yMax] in font units */ readonly bbox: [number, number, number, number]; /** StemV approximation for PDF font descriptor */ readonly stemV: number; /** Number of glyphs in the font */ readonly numGlyphs: number; /** Index-to-location format (0 = short offsets, 1 = long offsets) */ readonly indexToLocFormat: number; /** Number of horizontal metrics entries (from hhea) */ readonly numHMetrics: number; /** Table directory: tag → { offset, length } */ readonly tables: Map; /** Character-to-glyph ID mapping (Unicode code point → glyph ID) */ readonly cmap: Map; /** Advance widths per glyph ID (in font units) */ readonly advanceWidths: Uint16Array; /** Glyph offsets (from loca table), used for subsetting */ readonly glyphOffsets: Uint32Array; } export interface TableEntry { readonly offset: number; readonly length: number; } /** * Parse a TrueType font file. * * @param data - Raw .ttf or .otf file bytes * @returns Parsed font data * @throws {PdfFontError} If the font is invalid or unsupported */ export declare function parseTtf(data: Uint8Array): TtfFont;