import type { GlyphId, int16, uint16 } from "../../types.ts"; import type { Reader } from "../binary/reader.ts"; import type { GvarTable, PointDelta } from "./gvar.ts"; import type { LocaTable } from "./loca.ts"; /** * glyf table - Glyph outline data * Contains TrueType glyph contours as quadratic Bézier curves */ /** Point flags */ export declare const PointFlag: { readonly OnCurve: 1; readonly XShortVector: 2; readonly YShortVector: 4; readonly Repeat: 8; readonly XIsSameOrPositive: 16; readonly YIsSameOrPositive: 32; readonly OverlapSimple: 64; }; /** Composite glyph flags */ export declare const CompositeFlag: { readonly Arg1And2AreWords: 1; readonly ArgsAreXYValues: 2; readonly RoundXYToGrid: 4; readonly WeHaveAScale: 8; readonly MoreComponents: 32; readonly WeHaveAnXAndYScale: 64; readonly WeHaveATwoByTwo: 128; readonly WeHaveInstructions: 256; readonly UseMyMetrics: 512; readonly OverlapCompound: 1024; readonly ScaledComponentOffset: 2048; readonly UnscaledComponentOffset: 4096; }; /** A point in a glyph contour */ export interface GlyphPoint { x: number; y: number; onCurve: boolean; /** True if this is a cubic bezier control point (CFF fonts) */ cubic?: boolean; } /** A contour is a closed path of points */ export type Contour = GlyphPoint[]; /** Simple glyph with contours */ export interface SimpleGlyph { type: "simple"; numberOfContours: int16; xMin: int16; yMin: int16; xMax: int16; yMax: int16; contours: Contour[]; instructions: Uint8Array; } /** Component of a composite glyph */ export interface GlyphComponent { glyphId: GlyphId; flags: uint16; /** X offset or point number */ arg1: number; /** Y offset or point number */ arg2: number; /** Transformation matrix [a, b, c, d] */ transform: [number, number, number, number]; } /** Composite glyph made of other glyphs */ export interface CompositeGlyph { type: "composite"; numberOfContours: int16; xMin: int16; yMin: int16; xMax: int16; yMax: int16; components: GlyphComponent[]; instructions: Uint8Array; } /** Empty glyph (space, etc.) */ export interface EmptyGlyph { type: "empty"; } export type Glyph = SimpleGlyph | CompositeGlyph | EmptyGlyph; /** glyf table stores the raw reader for on-demand glyph parsing */ export interface GlyfTable { reader: Reader; } export declare function parseGlyf(reader: Reader): GlyfTable; /** * Parse a single glyph from the glyf table */ export declare function parseGlyph(glyf: GlyfTable, loca: LocaTable, glyphId: GlyphId): Glyph; /** * Flatten a composite glyph into simple contours * Recursively resolves all component glyphs and applies transformations */ export declare function flattenCompositeGlyph(glyf: GlyfTable, loca: LocaTable, glyph: CompositeGlyph, depth?: number): Contour[]; /** * Get all contours for a glyph, flattening composites */ export declare function getGlyphContours(glyf: GlyfTable, loca: LocaTable, glyphId: GlyphId): Contour[]; /** * Get contours and bounds for a glyph in one parse operation. * More efficient than calling getGlyphContours + getGlyphBounds separately. */ export declare function getGlyphContoursAndBounds(glyf: GlyfTable, loca: LocaTable, glyphId: GlyphId): { contours: Contour[]; bounds: { xMin: number; yMin: number; xMax: number; yMax: number; } | null; }; /** * Get bounding box for a glyph */ export declare function getGlyphBounds(glyf: GlyfTable, loca: LocaTable, glyphId: GlyphId): { xMin: number; yMin: number; xMax: number; yMax: number; } | null; /** * Get all deltas for a glyph at given variation coordinates */ export declare function getGlyphDeltas(gvar: GvarTable, glyphId: GlyphId, numPoints: number, axisCoords: number[], contours?: Contour[]): PointDelta[]; /** * Apply variation deltas to contours */ export declare function applyVariationDeltas(contours: Contour[], deltas: PointDelta[]): Contour[]; /** * Get contours for a glyph with variation applied */ export declare function getGlyphContoursWithVariation(glyf: GlyfTable, loca: LocaTable, gvar: GvarTable | null, glyphId: GlyphId, axisCoords?: number[]): Contour[];