@mlightcad/shx-parser
Version:
A TypeScript library for parsing AutoCAD SHX font files
44 lines (43 loc) • 2.1 kB
TypeScript
import { ShxShape } from './shape';
/** Default cell-width fraction added after ink width in {@link InkWidthAdvanceStrategy}. */
export declare const DEFAULT_INK_WIDTH_CELL_FACTOR = 0.2;
/**
* Resolves horizontal glyph advance for text layout.
*
* Each concrete strategy encapsulates one spacing model (SHX-native advance,
* ink-width proportional spacing, etc.).
*/
export declare abstract class ShxAdvanceWidthStrategy {
abstract resolve(shape: ShxShape, cellWidth: number): number;
/**
* Whether the aligned glyph should store the resolved advance as explicit.
* When false, {@link ShxShape.hasExplicitAdvance} is preserved from the source glyph.
*/
markAlignedAdvanceExplicit(_shape: ShxShape): boolean;
}
/** SHX pen advance with cell-width fallback (AutoCAD native model). */
export declare class ShxNativeAdvanceStrategy extends ShxAdvanceWidthStrategy {
resolve(shape: ShxShape, cellWidth: number): number;
}
/** Ink bbox width plus a fraction of the font cell width. */
export declare class InkWidthAdvanceStrategy extends ShxAdvanceWidthStrategy {
readonly cellWidthFactor: number;
constructor(cellWidthFactor?: number);
/**
* True when ink extends left of the glyph origin (UNIFONT center-cell encoding).
*/
static isCenterOriginGlyph(shape: ShxShape): boolean;
/**
* Resolves ink-based advance for a glyph at a scaled cell width.
*
* Left-origin glyphs (`minX >= 0`): `maxX + cellWidth * factor`.
* Center-origin glyphs (`minX < 0`): advance to the right cell edge
* (`max(maxX, cellWidth / 2)`) plus padding, so narrow centered punctuation
* keeps trailing whitespace instead of colliding with the next glyph.
*/
static computeAdvance(shape: ShxShape, cellWidth: number, cellWidthFactor?: number): number;
resolve(shape: ShxShape, cellWidth: number): number;
markAlignedAdvanceExplicit(_shape: ShxShape): boolean;
}
/** Default advance strategy using ink-width spacing with center-cell correction. */
export declare const defaultAdvanceWidthStrategy: InkWidthAdvanceStrategy;