UNPKG

@mlightcad/shx-parser

Version:

A TypeScript library for parsing AutoCAD SHX font files

73 lines (72 loc) 2.72 kB
import { Point } from './point'; /** * Represents a 2D bounding box with minimum and maximum coordinates */ export interface Box2d { minX: number; minY: number; maxX: number; maxY: number; } /** * Represents a shape defined by a collection of polylines and an optional last point. * Used to describe the geometry of a character in the SHX font. */ export declare class ShxShape { /** The last point in the shape's geometry, if any */ readonly lastPoint?: Point; /** Array of polylines, where each polyline is an array of points */ readonly polylines: Point[][]; /** * True when the SHX bytecode explicitly defines horizontal advance (pen-up moves, * BIGFONT cell primitive #2, etc.). Distinguishes Advance = 0 from "no advance defined". */ readonly hasExplicitAdvance: boolean; /** Cached bounding box to avoid recalculation */ private _bbox?; constructor(lastPoint?: Point, polylines?: Point[][], hasExplicitAdvance?: boolean); /** * Get the bounding box of the shape * @returns Bounding box of the shape */ get bbox(): Box2d; /** * Offset the shape by a point * @param p The point to offset the shape by * @param isNewInstance Whether to return a new instance of the shape or modify the current instance * @returns The offset shape */ offset(p: Point, isNewInstance?: boolean): ShxShape; /** * Normalizes a shape so that its bounding box’s bottom-left corner moves to the origin (0,0). * It doesn’t change the size or orientation, only repositions the shape. * @param isNewInstance Whether to return a new instance of the shape or modify the current instance * @returns The offset shape */ normalizeToOrigin(isNewInstance?: boolean): ShxShape; /** * Converts the shape to an SVG string * @param options SVG rendering options * @returns SVG string */ toSVG(options?: { strokeWidth?: string; strokeColor?: string; isAutoFit?: boolean; /** Fixed font-cell frame in layout coordinates (baseline at y = 0). */ fontCell?: { width: number; capHeight: number; descenderHeight: number; padding?: number; /** `baseline`: y grows upward from the baseline; `top`: y = 0 at the cell top. */ origin?: 'baseline' | 'top'; /** Expand the view box to include glyph ink outside the font cell. */ expandToFit?: boolean; /** Draw the SHX font cell bounds. */ showFrame?: boolean; frameColor?: string; frameStrokeWidth?: string; }; }): string; }