import type { GlyphId, TableRecord, Tag } from "../types.ts"; import { Reader } from "./binary/reader.ts"; import { type TtcHeader } from "./ttc.ts"; import { type AvarTable } from "./tables/avar.ts"; import { type BaseTable } from "./tables/base.ts"; import { type CbdtTable, type CblcTable } from "./tables/cbdt.ts"; import { type CffTable } from "./tables/cff.ts"; import { type Cff2Table } from "./tables/cff2.ts"; import { type CmapTable } from "./tables/cmap.ts"; import { type ColrTable } from "./tables/colr.ts"; import { type CpalTable } from "./tables/cpal.ts"; import { type FeatTable } from "./tables/feat.ts"; import { type FvarTable } from "./tables/fvar.ts"; import { type GaspTable } from "./tables/gasp.ts"; import { type GdefTable } from "./tables/gdef.ts"; import { type Contour, type GlyfTable, type Glyph } from "./tables/glyf.ts"; import { type GposTable } from "./tables/gpos.ts"; import { type GsubTable } from "./tables/gsub.ts"; import { type GvarTable } from "./tables/gvar.ts"; import { type HeadTable } from "./tables/head.ts"; import { type HheaTable } from "./tables/hhea.ts"; import { type CvtTable, type FpgmTable, type PrepTable } from "./tables/hinting.ts"; import { type HmtxTable } from "./tables/hmtx.ts"; import { type HvarTable } from "./tables/hvar.ts"; import { type JstfTable } from "./tables/jstf.ts"; import { type KernTable } from "./tables/kern.ts"; import { type KerxTable } from "./tables/kerx.ts"; import { type LocaTable } from "./tables/loca.ts"; import { type MathTable } from "./tables/math.ts"; import { type MaxpTable } from "./tables/maxp.ts"; import { type MorxTable } from "./tables/morx.ts"; import { type MvarTable } from "./tables/mvar.ts"; import { type NameTable } from "./tables/name.ts"; import { type Os2Table } from "./tables/os2.ts"; import { type PostTable } from "./tables/post.ts"; import { type SbixTable } from "./tables/sbix.ts"; import { type StatTable } from "./tables/stat.ts"; import { type SvgTable } from "./tables/svg.ts"; import { type TrakTable } from "./tables/trak.ts"; import { type VheaTable } from "./tables/vhea.ts"; import { type VmtxTable } from "./tables/vmtx.ts"; import { type VorgTable } from "./tables/vorg.ts"; import { type VvarTable } from "./tables/vvar.ts"; /** Font loading options */ export interface FontLoadOptions { /** Tables to parse eagerly (default: lazy) */ eagerTables?: Tag[]; /** TTC collection index (default: 0 when loading a TTC) */ collectionIndex?: number; } export interface CollectionFaceName { index: number; fullName?: string; family?: string; subfamily?: string; postScriptName?: string; } export declare class FontCollection { private readonly buffer; private readonly header; private readonly loadFace; private namesCache; constructor(buffer: ArrayBuffer, header: TtcHeader, loadFace: (index: number, options?: FontLoadOptions) => Font); get count(): number; get(index: number, options?: FontLoadOptions): Font; names(): CollectionFaceName[]; } /** * Represents a loaded font file. * Tables are parsed lazily on first access. */ export declare class Font { private readonly reader; private readonly directory; private _head; private _maxp; private _hhea; private _hmtx; private _cmap; private _gdef; private _gsub; private _gpos; private _kern; private _fvar; private _hvar; private _vhea; private _vmtx; private _morx; private _gvar; private _avar; private _kerx; private _trak; private _cff; private _cff2; private _colr; private _cpal; private _vvar; private _mvar; private _os2; private _name; private _post; private _base; private _jstf; private _math; private _loca; private _glyf; private _svg; private _vorg; private _sbix; private _stat; private _cbdt; private _cblc; private _feat; private _fpgm; private _prep; private _cvt; private _gasp; private constructor(); /** Load font from ArrayBuffer (sync - WOFF2 requires async loading) */ static load(buffer: ArrayBuffer, options?: FontLoadOptions): Font; /** Load font from ArrayBuffer with WOFF2 support (async) */ static loadAsync(buffer: ArrayBuffer, options?: FontLoadOptions): Promise; /** Load font from URL (works in browser and Bun, supports WOFF2) */ static fromURL(url: string, options?: FontLoadOptions): Promise; /** Load font from file path (Bun only, supports WOFF2) */ static fromFile(path: string, options?: FontLoadOptions): Promise; /** Create a TTC collection helper if buffer is a TrueType Collection */ static collection(buffer: ArrayBuffer): FontCollection | null; private static loadFromBuffer; private static loadFromTtc; /** Check if font has a specific table */ hasTable(tag: Tag): boolean; /** Get table record */ getTableRecord(tag: Tag): TableRecord | undefined; /** Get reader for a table */ getTableReader(tag: Tag): Reader | null; get head(): HeadTable; get maxp(): MaxpTable; get hhea(): HheaTable; get hmtx(): HmtxTable; get cmap(): CmapTable; get gdef(): GdefTable | null; get gsub(): GsubTable | null; get gpos(): GposTable | null; get kern(): KernTable | null; get fvar(): FvarTable | null; get hvar(): HvarTable | null; get vhea(): VheaTable | null; get vmtx(): VmtxTable | null; get morx(): MorxTable | null; get gvar(): GvarTable | null; get avar(): AvarTable | null; get kerx(): KerxTable | null; get trak(): TrakTable | null; get cff(): CffTable | null; get cff2(): Cff2Table | null; get colr(): ColrTable | null; get cpal(): CpalTable | null; get vvar(): VvarTable | null; get mvar(): MvarTable | null; get os2(): Os2Table | null; get name(): NameTable | null; get post(): PostTable | null; get base(): BaseTable | null; get jstf(): JstfTable | null; get math(): MathTable | null; get loca(): LocaTable | null; get glyf(): GlyfTable | null; get svg(): SvgTable | null; get vorg(): VorgTable | null; get sbix(): SbixTable | null; get stat(): StatTable | null; get cblc(): CblcTable | null; get cbdt(): CbdtTable | null; get feat(): FeatTable | null; get fpgm(): FpgmTable | null; get prep(): PrepTable | null; get cvtTable(): CvtTable | null; get gasp(): GaspTable | null; /** Number of glyphs in the font */ get numGlyphs(): number; /** Units per em */ get unitsPerEm(): number; /** Ascender (from hhea) */ get ascender(): number; /** Descender (from hhea) */ get descender(): number; /** Line gap (from hhea) */ get lineGap(): number; /** Line height (ascender - descender + lineGap for TrueType, ascender - descender for CFF) */ get height(): number; /** * Get scale factor for converting font units to pixels * @param sizePx Target size in pixels * @param mode Sizing mode: "em" (default) or "height" * @returns Scale factor to multiply font units by */ scaleForSize(sizePx: number, mode?: "em" | "height"): number; /** Is this a TrueType font (vs CFF)? */ get isTrueType(): boolean; /** Is this a CFF font? */ get isCFF(): boolean; /** Is this a variable font? */ get isVariable(): boolean; /** Has OpenType layout tables? */ get hasOpenTypeLayout(): boolean; /** Has AAT layout tables? */ get hasAATLayout(): boolean; /** Is this a color font? */ get isColorFont(): boolean; /** Does this font have TrueType hinting? */ get hasHinting(): boolean; /** Get glyph ID for a Unicode codepoint */ glyphId(codepoint: number): GlyphId; /** Get glyph ID for a character */ glyphIdForChar(char: string): GlyphId; /** Get advance width for a glyph */ advanceWidth(glyphId: GlyphId): number; /** Get left side bearing for a glyph */ leftSideBearing(glyphId: GlyphId): number; /** List all table tags in the font */ listTables(): string[]; /** Get raw glyph data (simple or composite) - TrueType only */ getGlyph(glyphId: GlyphId): Glyph | null; /** Get flattened contours for a glyph (resolves composites) */ getGlyphContours(glyphId: GlyphId): Contour[] | null; /** Get bounding box for a glyph */ getGlyphBounds(glyphId: GlyphId): { xMin: number; yMin: number; xMax: number; yMax: number; } | null; /** * Get contours and bounds for a glyph in a single operation. * More efficient than calling getGlyphContours + getGlyphBounds separately * as it only parses the glyph once. */ getGlyphContoursAndBounds(glyphId: GlyphId): { contours: Contour[]; bounds: { xMin: number; yMin: number; xMax: number; yMax: number; } | null; } | null; /** Get contours for a glyph with variation applied */ getGlyphContoursWithVariation(glyphId: GlyphId, axisCoords: number[]): Contour[] | null; }