@mlightcad/shx-parser
Version:
A TypeScript library for parsing AutoCAD SHX font files
72 lines (71 loc) • 2.8 kB
TypeScript
import { ShxFontData } from './fontData';
import { ShxShape } from './shape';
/**
* Parses SHX font data into shapes on demand. To improve performance, the shape is parsed on demand by
* character code and font size. Parsed shapes are cached.
*/
export declare class ShxShapeParser {
/** Font data of the font file */
private readonly fontData;
/** Cached shapes for performance. Key is `${code}_${size}` */
private shapeCache;
/** Shapes data. Key is the char code */
private shapeData;
constructor(fontData: ShxFontData);
/**
* Releases parsed shapes and cached shapes
*/
release(): void;
/**
* Parses a character's shape
* @param code - The character code
* @param size - The font size
* @returns The parsed shape or undefined if the character is not found
*/
parse(code: number, size: number): ShxShape | undefined;
/**
* Parses the shape of a character.
* @param data - The data of the character
* @param scale - The scale of the font
* @returns The parsed shape
*/
private parseShape;
/**
* Please refer to special codes reference in the following link for more information.
* https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-06832147-16BE-4A66-A6D0-3ADF98DC8228
* @param command - The command byte
* @param data - The data of the character
* @param index - The index of the command byte
* @param state - The state of the parser
* @returns The index of the next command byte
*/
private handleSpecialCommand;
private handleVectorCommand;
/**
* Get the vector for the given direction code. Please refer to the following link for more information.
* https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-0A8E12A1-F4AB-44AD-8A9B-2140E0D5FD23
* @param dir - The direction code of the vector
* @returns Returns the vector for the given direction code
*/
private getVectorForDirection;
private handleSubshapeCommand;
private handleXYDisplacement;
private handleMultipleXYDisplacements;
private handleOctantArc;
private handleFractionalArc;
private handleBulgeArc;
private handleMultipleBulgeArcs;
private skipCode;
private getShapeByCodeWithOffset;
/**
* Handles drawing an arc segment with the given vector and bulge
* @param currentPoint The starting point of the arc
* @param vec The displacement vector
* @param bulge The bulge value (will be normalized by 127.0)
* @param scale The current scale factor
* @param isPenDown Whether the pen is currently down (drawing)
* @param currentPolyline The current polyline being built
* @returns The new current point after the arc
*/
private handleArcSegment;
}