/** * Outline Transform Operations * * Provides geometric transformations for glyph outlines: * - 90° rotation * - Power-of-2 scaling * - 2D affine transforms (translate, rotate, scale, shear) * - 3D perspective transforms * - Bounding box computation */ import type { GlyphPath } from "./path.ts"; /** * 2D affine transformation matrix [a, b, c, d, tx, ty] * Transforms point (x, y) to: * x' = a*x + c*y + tx * y' = b*x + d*y + ty */ export type Matrix2D = [number, number, number, number, number, number]; /** * 3x3 transformation matrix for 2D homogeneous coordinates * | m00 m01 m02 | | x | | x' | * | m10 m11 m12 | × | y | = | y' | * | m20 m21 m22 | | 1 | | w | * * Final coordinates: (x'/w, y'/w) */ export type Matrix3x3 = [ [ number, number, number ], [ number, number, number ], [ number, number, number ] ]; /** * Axis-aligned bounding box */ export interface BoundingBox { xMin: number; yMin: number; xMax: number; yMax: number; } /** * Control box (bounding box of control points, not tight bounds) */ export interface ControlBox extends BoundingBox { } /** * Create identity 2D matrix */ export declare function identity2D(): Matrix2D; /** * Create identity 3x3 matrix */ export declare function identity3x3(): Matrix3x3; /** * Create translation matrix */ export declare function translate2D(tx: number, ty: number): Matrix2D; /** * Create scale matrix */ export declare function scale2D(sx: number, sy: number): Matrix2D; /** * Create rotation matrix (angle in radians) */ export declare function rotate2D(angle: number): Matrix2D; /** * Create shear/skew matrix */ export declare function shear2D(shearX: number, shearY: number): Matrix2D; /** * Multiply two 2D matrices: result = a × b */ export declare function multiply2D(a: Matrix2D, b: Matrix2D): Matrix2D; /** * Multiply two 3x3 matrices: result = a × b */ export declare function multiply3x3(a: Matrix3x3, b: Matrix3x3): Matrix3x3; /** * Transform a point using 2D matrix */ export declare function transformPoint2D(x: number, y: number, m: Matrix2D): { x: number; y: number; }; /** * Transform a point using 3x3 matrix (with perspective division) */ export declare function transformPoint3x3(x: number, y: number, m: Matrix3x3): { x: number; y: number; }; /** * Rotate outline by 90 degrees counter-clockwise around origin * Optionally apply offset after rotation */ export declare function rotateOutline90(path: GlyphPath, offsetX?: number, offsetY?: number): GlyphPath; /** * Scale outline by power of 2 * scaleOrdX/Y: shift amount (positive = enlarge, negative = shrink) * e.g., scaleOrdX=1 means multiply x by 2, scaleOrdX=-1 means divide by 2 */ export declare function scaleOutlinePow2(path: GlyphPath, scaleOrdX: number, scaleOrdY: number): GlyphPath; /** * Apply 2D affine transformation to outline */ export declare function transformOutline2D(path: GlyphPath, m: Matrix2D): GlyphPath; /** * Apply 3D perspective transformation to outline * Uses homogeneous coordinates for perspective projection */ export declare function transformOutline3D(path: GlyphPath, m: Matrix3x3): GlyphPath; /** * Compute control box (bounding box of all control points) * This is faster than computing tight bounds but may be larger */ export declare function computeControlBox(path: GlyphPath): ControlBox; /** * Compute tight bounding box (exact bounds considering curve extrema) */ export declare function computeTightBounds(path: GlyphPath): BoundingBox; /** * Update control box with transformed outline * Used for finding minimum X after 3D transform (like libass) */ export declare function updateMinTransformedX(path: GlyphPath, m: Matrix3x3, currentMinX: number): number; /** * Translate outline by offset */ export declare function translateOutline(path: GlyphPath, dx: number, dy: number): GlyphPath; /** * Scale outline uniformly */ export declare function scaleOutline(path: GlyphPath, sx: number, sy?: number): GlyphPath; /** * Rotate outline by angle (in radians) around origin */ export declare function rotateOutline(path: GlyphPath, angle: number): GlyphPath; /** * Apply italic/oblique shear to outline * @param angle Italic angle in degrees (typically 12-15 for italic) */ export declare function italicizeOutline(path: GlyphPath, angle: number): GlyphPath; /** * Create 3x3 perspective matrix * @param vanishingPointX X coordinate of vanishing point * @param vanishingPointY Y coordinate of vanishing point * @param strength Perspective strength (0 = none, larger = more perspective) */ export declare function perspectiveMatrix(vanishingPointX: number, vanishingPointY: number, strength: number): Matrix3x3; /** * Combine multiple paths into one */ export declare function combinePaths(paths: GlyphPath[]): GlyphPath; /** * Clone a path */ export declare function clonePath(path: GlyphPath): GlyphPath;