import type { GlyphBuffer } from "../buffer/glyph-buffer.ts"; import type { Font } from "../font/font.ts"; import type { Contour } from "../font/tables/glyf.ts"; import type { GlyphId } from "../types.ts"; import { type Matrix2D, type Matrix3x3 } from "./outline-transform.ts"; /** * Path command types for glyph rendering */ export type PathCommand = { type: "M"; x: number; y: number; } | { type: "L"; x: number; y: number; } | { type: "Q"; x1: number; y1: number; x: number; y: number; } | { type: "C"; x1: number; y1: number; x2: number; y2: number; x: number; y: number; } | { type: "Z"; }; /** * Outline flags (like FreeType's FT_OUTLINE_* flags) */ export declare enum OutlineFlags { /** No flags */ None = 0, /** Use even-odd fill rule instead of non-zero winding */ EvenOddFill = 1, /** Outline has been hinted */ HighPrecision = 2, /** Outline is a single stroke (not filled) */ SinglePass = 4 } /** * A glyph path is a series of drawing commands */ export interface GlyphPath { commands: PathCommand[]; bounds: { xMin: number; yMin: number; xMax: number; yMax: number; } | null; /** Outline flags (like FreeType's FT_OUTLINE_* flags) */ flags?: OutlineFlags; } /** * Convert contours to path commands * Handles both TrueType (quadratic Béziers) and CFF (cubic Béziers) */ export declare function contourToPath(contour: Contour): PathCommand[]; /** * Get cached glyph path, computing and caching if not already cached */ export declare function getGlyphPath(font: Font, glyphId: GlyphId): GlyphPath | null; /** * SVG coordinate scaling factor for sub-pixel precision. * Path data is output at 10x scale with integer coordinates, * viewBox is scaled to match, giving 0.1px precision with integer performance. */ export declare const SVG_SCALE = 10; /** * Convert path commands to SVG path data string * Outputs at SVG_SCALE (10x) with integer coordinates for performance * Caches results for default options (flipY=true, scale=1) */ export declare function pathToSVG(path: GlyphPath, options?: { flipY?: boolean; scale?: number; }): string; /** * Render options for stroke/fill */ export interface RenderOptions { flipY?: boolean; scale?: number; offsetX?: number; offsetY?: number; fill?: string; stroke?: string; strokeWidth?: number; lineCap?: CanvasLineCap; lineJoin?: CanvasLineJoin; miterLimit?: number; } /** * Render path commands to a Canvas 2D context */ export declare function pathToCanvas(ctx: CanvasRenderingContext2D | Path2D, path: GlyphPath, options?: { flipY?: boolean; scale?: number; offsetX?: number; offsetY?: number; }): void; /** * Generate an SVG element for a glyph */ export declare function glyphToSVG(font: Font, glyphId: GlyphId, options?: { fontSize?: number; fill?: string; stroke?: string; strokeWidth?: number; }): string | null; /** * Render shaped text to Canvas */ export interface ShapedGlyph { glyphId: GlyphId; xOffset: number; yOffset: number; xAdvance: number; yAdvance: number; } export declare function renderShapedText(ctx: CanvasRenderingContext2D, font: Font, glyphs: ShapedGlyph[], options?: { fontSize?: number; x?: number; y?: number; fill?: string; stroke?: string; strokeWidth?: number; lineCap?: CanvasLineCap; lineJoin?: CanvasLineJoin; /** 2D affine matrix to apply to glyph coordinates */ matrix?: Matrix2D; /** 3D perspective matrix to apply to glyph coordinates (takes precedence over matrix) */ matrix3D?: Matrix3x3; }): void; /** * Generate SVG for shaped text */ export declare function shapedTextToSVG(font: Font, glyphs: ShapedGlyph[], options?: { fontSize?: number; fill?: string; stroke?: string; strokeWidth?: number; lineCap?: "butt" | "round" | "square"; lineJoin?: "miter" | "round" | "bevel"; /** 2D affine matrix to apply to glyph coordinates */ matrix?: Matrix2D; /** 3D perspective matrix to apply to glyph coordinates (takes precedence over matrix) */ matrix3D?: Matrix3x3; /** If true, use native SVG transform attribute instead of transforming path data (2D only) */ useNativeTransform?: boolean; }): string; /** * Convert GlyphBuffer output to ShapedGlyph array */ export declare function glyphBufferToShapedGlyphs(buffer: GlyphBuffer): ShapedGlyph[]; /** * Get glyph path with variable font variation applied */ export declare function getGlyphPathWithVariation(font: Font, glyphId: GlyphId, axisCoords: number[]): GlyphPath | null; /** * Render shaped text with variable font support */ export declare function renderShapedTextWithVariation(ctx: CanvasRenderingContext2D, font: Font, glyphs: ShapedGlyph[], axisCoords: number[], options?: { fontSize?: number; x?: number; y?: number; fill?: string; stroke?: string; strokeWidth?: number; lineCap?: CanvasLineCap; lineJoin?: CanvasLineJoin; }): void; /** * Generate SVG for shaped text with variable font support */ export declare function shapedTextToSVGWithVariation(font: Font, glyphs: ShapedGlyph[], axisCoords: number[], options?: { fontSize?: number; fill?: string; stroke?: string; strokeWidth?: number; lineCap?: "butt" | "round" | "square"; lineJoin?: "miter" | "round" | "bevel"; }): string; /** * Calculate the total advance width of shaped text */ export declare function getTextWidth(glyphs: ShapedGlyph[], font: Font, fontSize: number): number; /** * Create a Path2D object from glyph path */ export declare function createPath2D(path: GlyphPath, options?: { flipY?: boolean; scale?: number; offsetX?: number; offsetY?: number; }): Path2D; /** * Render path to canvas with 2D affine matrix transformation applied to coordinates * The matrix transforms each point before drawing */ export declare function pathToCanvasWithMatrix(ctx: CanvasRenderingContext2D | Path2D, path: GlyphPath, matrix: Matrix2D, options?: { flipY?: boolean; }): void; /** * Convert path to SVG with 2D affine matrix transformation applied to coordinates */ export declare function pathToSVGWithMatrix(path: GlyphPath, matrix: Matrix2D, options?: { flipY?: boolean; }): string; /** * Render path to canvas with 3D perspective matrix transformation * Uses homogeneous coordinates for perspective projection */ export declare function pathToCanvasWithMatrix3D(ctx: CanvasRenderingContext2D | Path2D, path: GlyphPath, matrix: Matrix3x3, options?: { flipY?: boolean; }): void; /** * Convert path to SVG with 3D perspective matrix transformation * Uses homogeneous coordinates for perspective projection */ export declare function pathToSVGWithMatrix3D(path: GlyphPath, matrix: Matrix3x3, options?: { flipY?: boolean; }): string; /** * Apply 2D affine matrix to canvas context using native transform * Use ctx.save() before and ctx.restore() after to preserve context state */ export declare function applyMatrixToContext(ctx: CanvasRenderingContext2D, matrix: Matrix2D): void; /** * Convert 2D affine matrix to SVG transform attribute string * Returns a string like "matrix(a, b, c, d, tx, ty)" */ export declare function matrixToSVGTransform(matrix: Matrix2D): string; /** * Direct SVG serialization with transform applied in single pass * Avoids creating intermediate PathCommand arrays * Outputs at SVG_SCALE (10x) with integer coordinates for performance */ export declare function pathToSVGDirect(path: GlyphPath, scale: number, offsetX: number, offsetY: number): string;