/** * PathBuilder: Fluent builder for vector path operations * * Transforms are lazy by default - accumulated as matrix until rasterization or .apply() */ import type { Font } from "../font/font.ts"; import { type AsymmetricStrokeOptions } from "../raster/asymmetric-stroke.ts"; import type { Gradient } from "../raster/gradient.ts"; import { type MsdfOptions } from "../raster/msdf.ts"; import { type SdfOptions } from "../raster/sdf.ts"; import { type LineCap, type LineJoin, type StrokerOptions } from "../raster/stroker.ts"; import { type Matrix2D, type Matrix3x3 } from "../render/outline-transform.ts"; import { type GlyphPath } from "../render/path.ts"; import type { GlyphId } from "../types.ts"; import { BitmapBuilder } from "./bitmap-builder.ts"; import type { AutoRasterOptions, CanvasOptions, RasterOptions, SVGElementOptions, SVGOptions } from "./types.ts"; /** * PathBuilder provides a fluent interface for path transformations and rendering */ export declare class PathBuilder { private readonly _path; private readonly _transform; private readonly _font; private constructor(); /** * Create PathBuilder from a font glyph */ static fromGlyph(font: Font, glyphId: GlyphId): PathBuilder | null; /** * Create PathBuilder from a font glyph with variable font coordinates */ static fromGlyphWithVariation(font: Font, glyphId: GlyphId, axisCoords: number[]): PathBuilder | null; /** * Create PathBuilder from an existing GlyphPath */ static fromPath(path: GlyphPath): PathBuilder; /** * Combine multiple PathBuilders into one */ static combine(...builders: PathBuilder[]): PathBuilder; /** * Scale uniformly or non-uniformly */ scale(sx: number, sy?: number): PathBuilder; /** * Translate by offset */ translate(dx: number, dy: number): PathBuilder; /** * Rotate by angle in radians around origin */ rotate(angle: number): PathBuilder; /** * Rotate by angle in degrees around origin */ rotateDeg(angleDeg: number): PathBuilder; /** * Shear/skew transformation */ shear(shearX: number, shearY: number): PathBuilder; /** * Apply italic slant (angle in degrees, typically 12-15 for italic) */ italic(angleDeg: number): PathBuilder; /** * Apply custom 2D affine matrix */ matrix(m: Matrix2D): PathBuilder; /** * Reset transform to identity */ resetTransform(): PathBuilder; /** * Apply 3x3 perspective matrix */ perspective(m: Matrix3x3): PathBuilder; /** * Create perspective with vanishing point */ perspectiveVanish(vanishingPointX: number, vanishingPointY: number, strength: number): PathBuilder; /** * Force application of pending transforms * Returns new PathBuilder with transforms applied and reset */ apply(): PathBuilder; /** * Synthetic bold/embolden */ embolden(strength: number): PathBuilder; /** * Horizontal condensing (factor < 1) or expansion (factor > 1) */ condense(factor: number): PathBuilder; /** * Oblique/slant transformation */ oblique(slant: number): PathBuilder; /** * Convert to stroked outline */ stroke(options: StrokerOptions): PathBuilder; stroke(width: number, cap?: LineCap, join?: LineJoin): PathBuilder; /** * Asymmetric stroke with independent X/Y border widths * Returns outer and inner paths */ strokeAsymmetric(options: AsymmetricStrokeOptions): { outer: PathBuilder; inner: PathBuilder; }; /** * Asymmetric stroke combined (both inner and outer as single fillable path) */ strokeAsymmetricCombined(options: AsymmetricStrokeOptions): PathBuilder; /** * Get control box (bounding box of control points) * Note: Returns bounds AFTER applying transforms */ controlBox(): { xMin: number; yMin: number; xMax: number; yMax: number; }; /** * Get tight bounds (exact bounds considering curve extrema) * Note: Returns bounds AFTER applying transforms */ tightBounds(): { xMin: number; yMin: number; xMax: number; yMax: number; }; /** * Get the accumulated 2D transform matrix */ getTransformMatrix(): Matrix2D; /** * Get the accumulated 3D transform matrix (if any) */ getTransformMatrix3D(): Matrix3x3 | null; /** * Rasterize to bitmap with explicit size */ rasterize(options: RasterOptions): BitmapBuilder; /** * Rasterize with auto-computed size from bounds */ rasterizeAuto(options?: AutoRasterOptions): BitmapBuilder; /** * Rasterize with gradient fill */ rasterizeWithGradient(gradient: Gradient, options: RasterOptions): BitmapBuilder; /** * Render as Signed Distance Field (SDF) * Useful for GPU text rendering at any scale */ toSdf(options: SdfOptions): BitmapBuilder; /** * Render as SDF with auto-computed size from bounds */ toSdfAuto(options?: { padding?: number; scale?: number; spread?: number; flipY?: boolean; }): BitmapBuilder; /** * Render as Multi-channel Signed Distance Field (MSDF) * Better quality than SDF for sharp corners */ toMsdf(options: MsdfOptions): BitmapBuilder; /** * Render as MSDF with auto-computed size from bounds */ toMsdfAuto(options?: { padding?: number; scale?: number; spread?: number; flipY?: boolean; }): BitmapBuilder; /** * Convert to SVG path data string */ toSVG(options?: SVGOptions): string; /** * Convert to full SVG element string */ toSVGElement(options?: SVGElementOptions): string; /** * Render to canvas context */ toCanvas(ctx: CanvasRenderingContext2D, options?: CanvasOptions): void; /** * Get Path2D object for canvas */ toPath2D(options?: { flipY?: boolean; scale?: number; }): Path2D; /** * Extract the raw GlyphPath (with transforms applied) */ toPath(): GlyphPath; /** * Clone this builder */ clone(): PathBuilder; /** * Apply accumulated transforms to path */ private applyTransformToPath; /** * Check if there's any non-identity transform */ private hasTransform; /** * Check if 2D matrix is non-identity */ private hasTransform2D; /** * Combine accumulated 2D transform with render options */ private combinedMatrix2D; /** * Combine accumulated transforms into 3x3 matrix with render options */ private combinedMatrix3D; }